validate fields, then launch new window

G

Guest

Hi;

In a page, when the user clicks on a button, I want to validate all the
controls (in the code behind) and then if they are good, leave that page
alone and launch a new window with a new url also.

This is what I think is the best approach - please let me know if there is a
better one:

In my code behind I validate everything.
I then set a flag as a session variable.
I then have it reload the page I am in (do I redirect to the page or is
there another way?).
When the page loads, I look for the session variable and finding it, I
create an onload script.
The onload script launches a 2nd window to the other url. (Is there a best
way to do this and to specify the url so pop-up blockers don't block it?)
I have a javascript variable named launched I set to true after launching so
on a reload I don't launch again.

???
 
M

Mark Rae

In my code behind I validate everything.

Do you *actually* need to validate server-side? E.g. are you validating the
contents of the controls against a database...?
I then set a flag as a session variable.
I then have it reload the page I am in (do I redirect to the page or is
there another way?).
When the page loads, I look for the session variable and finding it, I
create an onload script.

??? Why do you need to reload the page at this point? Assuming you *do*
actually have to validate server-side, if validation passes why not simply
register a client script block...?
The onload script launches a 2nd window to the other url. (Is there a best
way to do this and to specify the url so pop-up blockers don't block it?)

If this is a public site, don't use showModalDialog as this doesn't work
with all browsers / versions. Use window.open instead.
I have a javascript variable named launched I set to true after launching
so
on a reload I don't launch again.

I think you may be over-complicating the process a bit...
 
W

Walter Wang [MSFT]

Hi David,

Thank you for your post.

In an ASP.NET Page's life cycle, some related events order is:
1) Load
2) Validation
3) Postback event handling

You can refer to following article for more info:

#ASP.NET Page Life Cycle Overview
http://msdn2.microsoft.com/en-us/library/ms178472.aspx

So I think you can simply check the IsValid property in the control event
which caused the postback, for example:

protected void Button1_Click(object sender, EventArgs e)
{
if (IsValid)
{
ClientScript.RegisterStartupScript(GetType(), "open2",
"javascript:window.open('default2.aspx')", true);
}
}

Hope this helps. Please feel free to post here if anything is unclear.

Regards,
Walter Wang
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 
G

Guest

Ok, will try this.

thanks - dave

ps - Yes unfortunately it needs to hit the DB for the validation.
 
W

Walter Wang [MSFT]

Hi David,

I am interested in this issue. Would you mind letting me know the result of
the suggestions? If you need further assistance, feel free to let me know.
I will be more than happy to be of assistance.

Have a great day!

Regards,
Walter Wang
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 
G

Guest

Hi;

I'm still fighting this. Two problems I am hitting:

1) popup blockers stop the popup.

2) what I want to do is when they click spawn a new browser and redirect the
existing page to a new page. The best I have come up with is I go to a 3rd
page that launches the new browser and then redirects - but I don't like this
solution.
 
W

Walter Wang [MSFT]

Hi Dave,

Thank you for your update.

As long as we're using JavaScript to open the new browser window, we cannot
do much with the popup blocker.

Do you think using Cross-Page PostBack here will be helpful? For example:

<form id="form1" runat="server">
<asp:Button id="button1" runat="server" text="button"
OnClientClick="form1.target='_blank';"
PostbackUrl="~/Default2.aspx"
</asp:Button>
</form>

This will survive the popup blocker, but Default2.aspx will always open.
And we need to check if the first page's valid or not in Default2.aspx:

if (PreviousPage != null) {
if (PreviousPage.IsValid) {
...
}
}

Hope this helps. Please feel free to post here if anything is unclear.



Regards,
Walter Wang ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 
G

Guest

When I get a popup on dell.com it comes up even though I have blocking on.
How do they manage this?
 
W

Walter Wang [MSFT]

Hi Dave,

I didn't see the popup on dell.com, do you mean that the popup gets opened
whenver you visit dell.com or when you click one of its hyperlinks? When
opening hyperlinks, if its target is set, it will open in another window.
But this is done without javascript, for example:

<a href="default2.aspx" target="_blank">here</a>

Also, most popup blockers can config some websites to be allowed to popup
new windows.

Regards,
Walter Wang ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 
W

Walter Wang [MSFT]

Thank you for your quick reply.

Do you need more discussion on this issue? Please feel free to post here.
Also, if you could provide more background and the requirement of your
project, maybe we could work out a better solution/workaround.

Have a nice day!

Regards,
Walter Wang ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 
J

JT

Hi,

This is more of a question than a suggestion, and it's based on what I
might do in ASP. I don't know if it would work in ASP.NET.

Can you post back to the first page to do the validation, then if it's
valid create a second form with all of the values that were entered as
"hidden" types (if that's necessary and/or possible), and perform an
automatic submission with the PostbackUrl set the way it is recommended
here? Naturally, this validation and resubmission would occur in the
code filtered by an If (IsPostback). If you haven't already found a
solution, let me know what you think of this. I may need it in the
future.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,067
Latest member
HunterTere

Latest Threads

Top