showModalDialog fires Page_Load only for first click

Just a simple problem, but without knowing the source of the problem,  quite a troublesome for you and also time wasting effort (just like me :P).

Ok, let met tell you my problem first. 

I have a function in javascript to display popup modal dialog window, to be simple i just put this function in HTML area not behind the code. This function will popup a window (aspx file) which is inside i execute some code behind function to databind my aspx controls with value from database, and again to be simple i just put all of this process in the Page_Load method.

The first time it run, everything run just like what i'm expected. But the problem occured when i tried to run the second time, i don't know why, but it seems the popup window aspx just don't like to rebinding the controls, as if the Page_Load method is never hit. I know this because the controls in the popup window just act like the same and previous one, although i have altered the value in the database. It's weird.

Everything is began to confussing me, i have tried other ways, like using RegisterClientScript or StartupScript in the code behind but still nothing is happened. (Previously i'm using OnClientClick in the button to execute the javascript function).

After a while, looking and searching for the same problem in Google, i just recogn that the source of the problem was : 

If the Page_Load event doesn't fire, then probably the page is loaded from the cache, and no roundtrip is made.

Finally, using a KISS (Keep It Simple and Stupid) method, i tried the simple thing, adding new parameter in the querystring of the popup with a value that will always change, something like date or time.

And this is the sample result of my solution : 

"popNew.aspx?" + new Date().getTime() + "&ID=" +pID

With this, the popup will always be reload by the asp.net engine (because it doesn't cache the page) and surely it will always hit the Page_Load method in the Code behind, and my page will always reflect the newest value from database.

my final full code for popup :

<script type="text/Javascript">

function PopUp()
{
    var myObject = new Object();
    var strUrl = "uc/GridSettings.aspx?" + new Date().getTime() + "&ID=" + modifyID;
    var params = window.showModalDialog(strUrl, myObject, "dialogHeight: 100px; dialogWidth: 200px; scroll: No;");
   
    if (params == "OK")
    {
       alert("Success");
    }
}

</script>

 
By. Tomy Ismail 

Share this post: | | | |
Published Tuesday, June 24, 2008 10:12 AM by tomysmile
Filed under: , ,

Comments

# re: showModalDialog fires Page_Load only for first click

Wednesday, July 23, 2008 7:07 PM by Joydeep Das

use this

<%@ OutputCache Duration="1" VaryByParam="*"%>

Powered by Community Server (Commercial Edition), by Telligent Systems