Go Premium for a chance to win a PS4. Enter to Win


Gridview SelectedIndexChanged showModalDialogue problem when browser back button is pressed

Posted on 2009-05-14
Medium Priority
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

Question by:johnny_32
  • 3
  • 2
LVL 39

Expert Comment

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.
LVL 39

Expert Comment

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

Expert Comment

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...

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.


Accepted Solution

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

Expert Comment

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.
LVL 10

Expert Comment

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!

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
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.
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

916 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