Solved

Gridview SelectedIndexChanged showModalDialogue problem when browser back button is pressed

Posted on 2009-05-14
6
710 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Loop not working 29 47
Name space syntax error 12 39
Angular JS Route 3 45
Master Content Pages, WebForms, and Session Variables 1 29
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This is a video describing the growing solar energy use in Utah. This is a topic that greatly interests me and so I decided to produce a video about it.

932 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

8 Experts available now in Live!

Get 1:1 Help Now