Advertisement

03.28.2008 at 06:12AM PDT, ID: 23277027
[x]
Attachment Details

How do I prevent RegisterClientScriptBlock() from executing on page refresh/reload?

Asked by VernonHarvey in Visual Studio .NET 2005, Programming for ASP.NET, WebApplications

Hello all:

I have an ASP.Net web page that is my login page to an application.  It has a "Login" button that validates the user account details and then calls ClientScript.RegisterClientScriptBlock() to open another .ASPX page containing my actual application window.  It does this using javascript and suppresses all the IE user controls such as the address bar and other tool bars.  I clear the password entry field on the login page, so that the user does not simply hit the "Login" button again to login into the website.

This all works fine when I login into the site, just as I intended.  My problem is three-fold, but related.

1)  If the user closes the application window so that they are back on the login page, and then hits the "Refresh" button on Internet Explorer, they get a prompt saying "To display the webpage again, IE needs to ersend the information  you've previously submitted".  If they hit the "Retry" button on that pop-up message, they are automatically logged into the site without having to re-enter the login password.

2)  If the user closes the application window (returning them to the login window) and then navigates to another web page (such as www.experts-exchange.com) then hits the "back" button to return to my login page, the login page appears, but my applicaiton window also pops open again without the user having entered their password or pressing the "Login" button.

3)  If the user switches from the application window (so that it is still open, but in the background) back to the login page and either refreshes or navigates away and back, a second copy of the application window is opened.

I think the problem has something to do with the way that the "RegisterClientScriptBlock() API works (unfortunately, this is not my code and the guys that wrote it no longer works here any more).   On the "OnClick" event in the login2.aspx.cs code behind code, I call RegisterClientScriptBlock() as follows:

ClientScript.RegisterClientScriptBlock(this.GetType(), "redirect", "<script language=\"javascript\" type=\"text/javascript\">window.open( 'Default.aspx', '_blank', 'resizable=yes,menubar=no,toolbar=no,location=no,scrollbars=yes,status=yes,width=1024,height=768,left=10,top=10');</script>");

After the application page is displayed, if I look at the source for the login page, I noticed that there are three new sections added:

There is the viewstate section:
<div><input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUKLTg4ODg2NjU5MA9kFgICAQ9kFgICCQ8PFgIeBFRleHRlZGRkmGv+kbngmmKxfTVrZrAZlxprlg4=" /></div>

The new javascript
<script language="javascript" type="text/javascript">window.open('Default.aspx', '_blank', 'resizable=yes,menubar=no,toolbar=no,location=no,scrollbars=yes,status=yes,width=1024,height=768,left=10,top=10');</script>

and finally the event validation section:
<div><input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="/wEWBQL88ZOWDgL7h7XbDwKF+9bXBQLKw6LdBQKC3IeGDOy02aq/oOP3fpdcqXCX9/j+KmSw" /></div>

Is there some way to clear this code or Deregister it?  Or is there an event I can use to tell if I am in a page refresh or reload scenario (I know there is a "Page_Load" event being processed, are there other events that I could be monitoring?

Any help would be greatly appreciated.Start Free Trial
 
 
[+][-]03.28.2008 at 06:57AM PDT, ID: 21230393

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]03.28.2008 at 10:52AM PDT, ID: 21232653

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]03.28.2008 at 11:20AM PDT, ID: 21232876

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.16.2008 at 06:51AM PDT, ID: 21367715

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.16.2008 at 08:13AM PDT, ID: 21368683

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Visual Studio .NET 2005, Programming for ASP.NET, WebApplications
Sign Up Now!
Solution Provided By: jcoehoorn
Participating Experts: 1
Solution Grade: B
 
 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628