ASP.NET Javascript Modal Popup won't fire Page Load on second go

Discussion in 'ASP .Net' started by H00ner, Aug 17, 2005.

  1. H00ner

    H00ner Guest

    Hello All

    Hope you can help

    Been pulling my hair out about a popup problem in ASP.NET. One of the
    forms i wrote requires the user to select a product from a list in a
    popup web form. the popup has a DataGrid on it and the page.load
    function DataBinds as you'd expect.

    I have Code-Behind in C# to emit a call to a JavaScript function which
    uses showModalDialog() to show the popup. The product list is selected
    from the parent page and inserted into a Session[] variable. This
    Session[] variable is picked up by the popup and binds to the datagrid
    successfully. A little more JavaScript is emitted in the popup to get
    an array of data back to the parent, and also call window.close().

    However, when the user has to select a second product, the popup
    doesn't fire it's Page.load method and the DataGrid remains with it's
    old data. The data is definitely in the Session[] store as i expected
    it.

    How can i get the popup to close properly so that the page.load event
    fires every time?

    hope it makes sense
     
    H00ner, Aug 17, 2005
    #1
    1. Advertising

  2. H00ner

    Curt_C [MVP] Guest

    Re: ASP.NET Javascript Modal Popup won't fire Page Load on secondgo

    > How can i get the popup to close properly so that the page.load event
    > fires every time?
    >


    Not sure but I think the window.open() call has an attribute to name the
    opening window (for ref) and if so try generating a random name (time
    perhaps) as the name to ensure it's a "new" window...

    Just a quick thought

    --
    Curt Christianson
    site: http://www.darkfalz.com
    blog: http://blog.darkfalz.com
     
    Curt_C [MVP], Aug 17, 2005
    #2
    1. Advertising

  3. if i've understood this properly, you are trying to get the Parent page to
    reload once you have finished with the popup window.

    If this is the case, as well as closing the popup, try redirect the Parent
    page to itself

    JavaScript: window.opener.parent.location='MyUrl.aspx';

    HTH





    "H00ner" <> wrote in message
    news:...
    > Hello All
    >
    > Hope you can help
    >
    > Been pulling my hair out about a popup problem in ASP.NET. One of the
    > forms i wrote requires the user to select a product from a list in a
    > popup web form. the popup has a DataGrid on it and the page.load
    > function DataBinds as you'd expect.
    >
    > I have Code-Behind in C# to emit a call to a JavaScript function which
    > uses showModalDialog() to show the popup. The product list is selected
    > from the parent page and inserted into a Session[] variable. This
    > Session[] variable is picked up by the popup and binds to the datagrid
    > successfully. A little more JavaScript is emitted in the popup to get
    > an array of data back to the parent, and also call window.close().
    >
    > However, when the user has to select a second product, the popup
    > doesn't fire it's Page.load method and the DataGrid remains with it's
    > old data. The data is definitely in the Session[] store as i expected
    > it.
    >
    > How can i get the popup to close properly so that the page.load event
    > fires every time?
    >
    > hope it makes sense
    >
     
    Grant Merwitz, Aug 17, 2005
    #3
  4. and just found on google, you can also do:

    JavaScript: window.opener.location.reload()

    "H00ner" <> wrote in message
    news:...
    > Hello All
    >
    > Hope you can help
    >
    > Been pulling my hair out about a popup problem in ASP.NET. One of the
    > forms i wrote requires the user to select a product from a list in a
    > popup web form. the popup has a DataGrid on it and the page.load
    > function DataBinds as you'd expect.
    >
    > I have Code-Behind in C# to emit a call to a JavaScript function which
    > uses showModalDialog() to show the popup. The product list is selected
    > from the parent page and inserted into a Session[] variable. This
    > Session[] variable is picked up by the popup and binds to the datagrid
    > successfully. A little more JavaScript is emitted in the popup to get
    > an array of data back to the parent, and also call window.close().
    >
    > However, when the user has to select a second product, the popup
    > doesn't fire it's Page.load method and the DataGrid remains with it's
    > old data. The data is definitely in the Session[] store as i expected
    > it.
    >
    > How can i get the popup to close properly so that the page.load event
    > fires every time?
    >
    > hope it makes sense
    >
     
    Grant Merwitz, Aug 17, 2005
    #4
  5. H00ner

    H00ner Guest

    I saw that option of window.open() but, unfortunately, I'm using
    window.showModalDialog() which returns a variant from the modal box and
    not a reference to the page.

    thanks for the reply though Curt :¬)
     
    H00ner, Aug 17, 2005
    #5
  6. H00ner

    Curt_C [MVP] Guest

    Re: ASP.NET Javascript Modal Popup won't fire Page Load on secondgo

    Grant Merwitz wrote:
    > if i've understood this properly, you are trying to get the Parent page to
    > reload once you have finished with the popup window.
    >


    Actually I think he's indicating that the second time he tries to call
    the window.open() it doesnt.... because he suspects it isnt closing
    properly??

    --
    Curt Christianson
    site: http://www.darkfalz.com
    blog: http://blog.darkfalz.com
     
    Curt_C [MVP], Aug 17, 2005
    #6
  7. H00ner

    H00ner Guest

    thanks Grant, but it's not the parent that needs to be reloaded.

    The process works like this :

    Parent window selects data to be displayed in popup and stores in
    session
    Parent emits javascript to call showModalDialog() and popup loads
    Popup gets data from session and binds to datagrid
    User selects data they want and popup returns a JavaScript array
    Parent uses javascript array to fill text boxes

    This all works okay on the first run through, but the popup will not
    fire it's Server-Side Page.Load method when it's called a Second time
    and the new data selected by the parent isn't bound to the DataGrid.
    It seems that the popup page is still 'loaded' and the JavaScript
    window.close() doesn't unload it entirely
     
    H00ner, Aug 17, 2005
    #7
  8. H00ner

    Curt_C [MVP] Guest

    Re: ASP.NET Javascript Modal Popup won't fire Page Load on secondgo

    H00ner wrote:
    > I saw that option of window.open() but, unfortunately, I'm using
    > window.showModalDialog() which returns a variant from the modal box and
    > not a reference to the page.
    >
    > thanks for the reply though Curt :¬)
    >


    I'm not really concerned with the return from the call, more of the
    actual call. I was just wondering if the browser was seeing the same
    call twice and not calling it.. was thinking that an appended
    QueryString random value or new name may "fool" the browser into
    thinking its a different window.

    Personally I've avoided the modal windows due to the NASTY problems I
    always run into. A well placed/positioned window.open() call is usually
    sufficient. It is definitely an area that WWW has a deficiency in.


    --
    Curt Christianson
    site: http://www.darkfalz.com
    blog: http://blog.darkfalz.com
     
    Curt_C [MVP], Aug 17, 2005
    #8
  9. H00ner

    H00ner Guest

    You could be on to something there Curt. I was trying to force the
    users to give me the data using a modal dialog box. However, i could
    use a window.open() instead really as this does give a reference to the
    window i've opened which i should be able to nullify when i'm done

    thanks for your feedback (and you, Grant) on my issue. I'll update
    this thread with my findings using window.open() instead of
    window.showModalDialog()

    You're also right about the deficiancy thing as well. i'm hoping
    there's something to help us more when ASP.NET 2.0 emerges :¬)

    cheers

    Tim
     
    H00ner, Aug 17, 2005
    #9
  10. H00ner

    Curt_C [MVP] Guest

    Re: ASP.NET Javascript Modal Popup won't fire Page Load on secondgo

    > You're also right about the deficiancy thing as well. i'm hoping
    > there's something to help us more when ASP.NET 2.0 emerges :¬)
    >


    Sadly its not a programming limitation that much.. mostly its a Browser
    thing. WWW wasn't really designed around the idea of multiple,
    interconnected, windows. It was supposed to be a single call, processed
    and returned then dropped. Everything beyond that is really just
    "project drift"......

    -
    Curt Christianson
    site: http://www.darkfalz.com
    blog: http://blog.darkfalz.com
     
    Curt_C [MVP], Aug 17, 2005
    #10
  11. H00ner

    H00ner Guest

    i've had a think about the window.open() thing as well and my project
    relies on the returned array from showModalDialog() so it can collect
    the data into the desired boxes.

    do you know if there's any way of calling a page's Dispose() method
    from another page? Maybe i could ensure the page is unloaded before I
    emit the JavaScript to pop the box up

    i'll have another play tomorrow and see what happens

    thanks for all your suggestions :¬)

    Tim
     
    H00ner, Aug 17, 2005
    #11
  12. Re: ASP.NET Javascript Modal Popup won't fire Page Load on second

    "H00ner" wrote:
    > but the popup will not
    > fire it's Server-Side Page.Load method when it's called a Second time
    > and the new data selected by the parent isn't bound to the DataGrid.
    > It seems that the popup page is still 'loaded' and the JavaScript
    > window.close() doesn't unload it entirely


    Page loads the previous data, when clicked second time ?

    The issue should be BROWSER CACHING the data.. use this code in popup page
    page_load to expire the cache..


    private void Page_Load(object sender, System.EventArgs e)
    {
    ExpirePageCache();
    //.......rest of the page_load logic....................
    }


    /// <summary>
    /// This function prevent the page being retrieved from broswer cache
    /// </summary>
    private void ExpirePageCache()
    {
    Response.Cache.SetCacheability(HttpCacheability.NoCache);
    Response.Cache.SetExpires(DateTime.Now-new TimeSpan(1,0,0));
    Response.Cache.SetLastModified(DateTime.Now);
    Response.Cache.SetAllowResponseInBrowserHistory(false);
    }



    pls let us know if it worked.. Thanks

    Sreejith
     
    =?Utf-8?B?U3JlZWppdGggUmFt?=, Aug 17, 2005
    #12
  13. Re: ASP.NET Javascript Modal Popup won't fire Page Load on second

    an additional note, this happense when you do not have any query parameter
    passed (or pass same query param value in susequent calls) to the popup ..

    Adding a dummy query parameter param with some random value passed as
    parameter every time also could solve the issue..

    "Sreejith Ram" wrote:

    > "H00ner" wrote:
    > > but the popup will not
    > > fire it's Server-Side Page.Load method when it's called a Second time
    > > and the new data selected by the parent isn't bound to the DataGrid.
    > > It seems that the popup page is still 'loaded' and the JavaScript
    > > window.close() doesn't unload it entirely

    >
    > Page loads the previous data, when clicked second time ?
    >
    > The issue should be BROWSER CACHING the data.. use this code in popup page
    > page_load to expire the cache..
    >
    >
    > private void Page_Load(object sender, System.EventArgs e)
    > {
    > ExpirePageCache();
    > //.......rest of the page_load logic....................
    > }
    >
    >
    > /// <summary>
    > /// This function prevent the page being retrieved from broswer cache
    > /// </summary>
    > private void ExpirePageCache()
    > {
    > Response.Cache.SetCacheability(HttpCacheability.NoCache);
    > Response.Cache.SetExpires(DateTime.Now-new TimeSpan(1,0,0));
    > Response.Cache.SetLastModified(DateTime.Now);
    > Response.Cache.SetAllowResponseInBrowserHistory(false);
    > }
    >
    >
    >
    > pls let us know if it worked.. Thanks
    >
    > Sreejith
    >
     
    =?Utf-8?B?U3JlZWppdGggUmFt?=, Aug 17, 2005
    #13
  14. H00ner

    Curt_C [MVP] Guest

    Re: ASP.NET Javascript Modal Popup won't fire Page Load on secondgo

    H00ner wrote:
    > i've had a think about the window.open() thing as well and my project
    > relies on the returned array from showModalDialog() so it can collect
    > the data into the desired boxes.
    >
    > do you know if there's any way of calling a page's Dispose() method
    > from another page? Maybe i could ensure the page is unloaded before I
    > emit the JavaScript to pop the box up
    >
    > i'll have another play tomorrow and see what happens
    >
    > thanks for all your suggestions :¬)
    >
    > Tim
    >


    save the data, call the calling-pages Refresh() when complete

    --
    Curt Christianson
    site: http://www.darkfalz.com
    blog: http://blog.darkfalz.com
     
    Curt_C [MVP], Aug 17, 2005
    #14
  15. H00ner

    H00ner Guest

    Re: ASP.NET Javascript Modal Popup won't fire Page Load on second

    Sreejith

    These both worked.

    i added a javascript method to return a random generated querystring
    which i then appended to my URL in showModalDialog() and this caused
    the page to load every time

    Also, i tried the Response.Cache() method you gave me and that works
    also. i prefer this method to the random querystring as the code is
    all server-side and easy to locate

    thanks your help on this, problem solved :¬)

    Tim
     
    H00ner, Aug 18, 2005
    #15
  16. H00ner

    H00ner Guest

    it's a bit of a weird page in most respects. the page starts by asking
    the user to select one of our clients and then goes off to cache the
    client's product list so that the popup loads a bit quicker. this
    selection also makes visible a whole swath of panels and tables with
    fields in them.

    Sreejith had the solution up above and it was due to browser caching.
    invalidating the cache or tricking the browser into thinking it's a
    different link sorted it out :¬)

    I'd like to thank you all for your time on my issue and replying to me.
    it's really helped me out

    cheers

    Tim
     
    H00ner, Aug 18, 2005
    #16
  17. H00ner

    Raja Jayabal

    Joined:
    Nov 3, 2008
    Messages:
    1
    Reg Window.Showmodal()

    Hi,

    If you use window.open() then the parent page will be editable or active.
    If you dont want the parent page to be active, then you have to open the pop up using hte below code only

    window.showmodal(xxxxxx);

    now the question who have is, it's not firing the form load of the pop up page,

    for that to happen just write the piece of code at the top of the pop up ASPX page

    <% Response.Expires = -1%>

    This code should be the first line in the ASPX page of the popup window,

    Now when ever the page is loded it will just kill the page add reopen it freshly, so the page load will happen every time you load the popup..

    Thanks,

    Raja Jayabal.
     
    Raja Jayabal, Nov 3, 2008
    #17
  18. H00ner

    Val0412

    Joined:
    Nov 25, 2008
    Messages:
    1
    Location:
    FL
    ^
    We've also confirmed that all three work beautifully.

    We've decided to go with the single line of code in the aspx page.

    This has been a huge help.

    Thanks Everyone.
     
    Val0412, Nov 25, 2008
    #18
  19. H00ner

    cunhajo

    Joined:
    Aug 4, 2009
    Messages:
    1
    I beleive I found a solution to your problem.

    I found some code on another forum that seems to resolve the very problem you describe. I had the same problem. Modal Form would open firing page load first time, but not subsequent times, and not run code behind, resulting in incorrect data.

    I placed the following code in the initial form load of the modal window, and it now runs the form load every time after closing it. I beleive the modal form was possibly being cached, and no really re-opening every time. Now it does. Hope this helps.

    Response.Expires = 0
    Response.Cache.SetNoStore()
    Response.AppendHeader("Pragma", "no-cache")
     
    cunhajo, Aug 4, 2009
    #19
  20. H00ner

    topraveen

    Joined:
    Jul 20, 2010
    Messages:
    1
    Hi,
    please use this the following on your pages asax file.
    <%@ OutputCache Duration="1" VaryByParam="*"%>
    its works for me very well.

    thanks praveen.
     
    topraveen, Jul 20, 2010
    #20
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Brian Henry

    showing modal popup window after page load

    Brian Henry, Jul 4, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    1,355
    Marc Jennings
    Jul 5, 2004
  2. Phil Winstanley [Microsoft MVP ASP.NET]

    Re: showing modal popup window after page load

    Phil Winstanley [Microsoft MVP ASP.NET], Jul 4, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    5,939
    Brian Henry
    Jul 4, 2004
  3. Replies:
    0
    Views:
    369
  4. Don
    Replies:
    0
    Views:
    356
  5. Replies:
    1
    Views:
    239
    Yann-Erwan Perio
    Jun 8, 2005
Loading...

Share This Page