Solved

Gridview SelectedIndexChanged showModalDialogue problem when browser back button is pressed

Posted on 2009-05-14
6
709 Views
Last Modified: 2012-05-07
I have been stuck on this problem for far too long and wondered if anybody can help. I have a gridview and when a user clicks on a row a showmodaldialogue popup displays on the Grdiviews SelectedIndexChanged.  This is fine but if the user navigates away from the page and clicks the browser back button the showmodialogue popups automatically without the user clicking on the gridview.  How can i prevent the showmodaldialogue from popping up when the back button is pressed?
protected void grd_FlooringSummary_SelectedIndexChanged(object sender, EventArgs e)

    {

        string f_id = grd_FlooringSummary.SelectedValue.ToString();

        string strPage = "../databases/inw/Flooring.htm?cp_no=" + f_id;

 

string  strScript = "";

strScript = "<script type='text/javascript'>window.showModalDialog('" + strPage + "','','dialogWidth:65em;dialogHeight:57em;scroll:no;status:off');</script>";

ClientScript.RegisterStartupScript(this.GetType(), "AvisoScript", strScript);

 

    }

Open in new window

0
Comment
Question by:johnny_32
  • 3
  • 2
6 Comments
 
LVL 39

Expert Comment

by:abel
ID: 24386643
You apparently show the modal dialog after the user has clicked and the page is refreshed. That means that the browser sees only the new page and not the old page, and the new page (the page the way it looks after FlooringSummary has change) has the startup script at the beginning.

The simplest way would be to add a little to your startup script. I.e., set a cookie that tracks whether it was called already or not.

Alternatively, you can set the .NoStore(). That way, the browser will not cache the page. The next time you come at the page (with back or whatever) the page will be refreshed and will load as if it was loaded the first time around.
0
 
LVL 39

Expert Comment

by:abel
ID: 24386654
That is: Response.Cache.SetNoStore() actually.
0
 
LVL 10

Expert Comment

by:MaxOvrdrv2
ID: 24386666
in short... you can't...

in long... you can... but you would have to mess with the BeforeUnload, and that's a mess you don't wanna start playing with... unless someone has a better idea?

the problem is that you cannot know if someone is viewing your page from the back button... so all you could do is unload all of the modals if the application is being terminated (close window, navigate away from the application site, etc)... but that to me is such a pain to program its not even worth it...

but someone might have a better answer... who knows...
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 

Accepted Solution

by:
johnny_32 earned 0 total points
ID: 24451549
Managed to solve this myself. Simply used Gridview RowDataBound event instead and this worked fine.
0
 
LVL 39

Expert Comment

by:abel
ID: 24451612
That can only work if you bind the data outside the "if IsPostBack" block. Otherwise, what you state in the question, the back-button may still load the cached version. if you do not want it cached, you should still use the NoStore approach.

anyway, glad you found a solution that worked for you.
0
 
LVL 10

Expert Comment

by:MaxOvrdrv2
ID: 24481955
yes i second that... it doesn't really solve the back button since the page doesn't actually "refresh" when you hit the back button, unless you fire off an event. But hey, if it works for you, tant mieux!
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now