Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Gridview SelectedIndexChanged showModalDialogue problem when browser back button is pressed

Posted on 2009-05-14
6
Medium Priority
?
724 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

664 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