Solved

Gridview SelectedIndexChanged showModalDialogue problem when browser back button is pressed

Posted on 2009-05-14
6
716 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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
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 …
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

820 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