Поделиться через


ShowModalDialog

I noticed that the following is an issue thru which people often run: when you show an aspx page (or any server content in general) in a dialog by mean of the javascript ShowModalDialog method, at the first postback you usually witness the instance of a second window, his time a full blown browser, holding in your output.

There is an easy workaround to the situation, but surprisingly it seems that few people knows it: so I'm posting it.

The trick is showing a static page , a simple .htm, in the ShowModalDialog call; such page should hold the active content (your .aspx) in an IFRAME. Subsequent posts will be confined inside the iframe, hence restoring the intended user exprerience.

UPDATE

J proposes a more efficient system: <base target="_self">  in the header of the aspx page yelds to the same result. Thank you J :-)

Comments

  • Anonymous
    June 05, 2003
    <base target="_self">

    Sticking that in the header of the ASPX page you're targetting with .showModalDialog() gets the same results....without resorting to the overhead of IFRAME.

    - J
  • Anonymous
    June 05, 2003
    Hasn't the target attribute been deprecated?
  • Anonymous
    June 05, 2003
    IIRR turning smartnavigation ON on the aspx that appears in the modal dialog window also gets around this problem. YMMV.
  • Anonymous
    June 19, 2003
    HI,

    I've been struggling with this all day. I used the dummy <Iframe> .html, but had a hard time getting the returnvalue.

    I put in the <base....> tag info and that works.

    But I am still having trouble getting the returnvalue.

    In my Parent window I have
    code....
    arrModal = window.showModalDialog
    ("popup.asp",, _
    "dialogHeight:30;
    dialogWidth:33;edge:Raised;center:Yes;help:No;resizable:No;status:No;")

    msgbox arrmodal


    in my popup window I have.

    code.....
    window.returnvalue = "HERE I BE"
    window.close

    The value of arrModal in the parent window when the popup is close is null.


    any ideas? It seems so straight forward.

  • Anonymous
    June 19, 2003
    Elisabeth, I've heard of this from others but I never had the time to actually check it out. If you don't have problems of security/confidentiality of data, I know that a lot of people used this workaround: you can put your results on a cookie generated for the purpose (use as ID a GUID supplied from the caller at the dialog opening) and retrieve (and delete) it from the caller page as the dialog closes. Let me know if it worked for you.
  • Anonymous
    August 07, 2003
    11
  • Anonymous
    September 10, 2003
    window.returnvalue = "HERE I BE"
    should be

    window.returnValue = "HERE I BE"
  • Anonymous
    November 01, 2003
    The comment has been removed
  • Anonymous
    December 05, 2003
    eth45yh4hy
  • Anonymous
    January 07, 2004
    dfg
  • Anonymous
    January 27, 2004
    thanks this fix really got me out of a jam ...
  • Anonymous
    January 29, 2004
    The comment has been removed
  • Anonymous
    March 02, 2004
    dfsa
  • Anonymous
    March 30, 2004
    ssdfsdf
  • Anonymous
    April 07, 2004
    test
  • Anonymous
    April 16, 2004
    fsda
  • Anonymous
    May 03, 2004
    dg
  • Anonymous
    May 17, 2004
    asodjsodjweodjwedwe
  • Anonymous
    May 17, 2004
    ssss
  • Anonymous
    May 26, 2004
    Thanks a lot !
    I used solution with <base.. /> and i works great.

    Tomas
  • Anonymous
    June 02, 2004
    <center><b>you</b>
  • Anonymous
    June 23, 2004
    does the <base target="_self"> work with modal .jsp files too...i tried it ..doesn't work
  • Anonymous
    June 25, 2004
    test
  • Anonymous
    June 25, 2004
    test
  • Anonymous
    July 20, 2004
    I had trouble getting the return value.
    I dont know why, but everytime I tried to get the value I just got undefined.

    What you can is to define a variable in the opener window and then pass it as the dialogArguments and modify it like:
    window.dialogArguments = "new value"

    or even better, you can pass the window object as a reference and then update or use any variable.
    window.dialogArguments.var1 = "new value";
    window.dialogArguments.var2 = "new value";

    just open the window this way:
    window.showModalDialog("url.htm",window);


    I hope this helps.

    By the way, thanks for the other tips. I've tried none, but I hope one of those will work for me.

    It's weird that doesnt happens with html pages.




  • Anonymous
    August 05, 2004
    Great tip!
    The <base target="_self"> part works great for me!
    Thank you very much!

    Davide
  • Anonymous
    October 21, 2004
    The comment has been removed
  • Anonymous
    September 07, 2010
    <base target="_self"> its working in first level of popup .. but am using second level its working in Firefox kindly do the needful. -sundar