showModalDialog window does not close

Discussion in 'ASP .Net' started by Stan B, Oct 16, 2006.

  1. Stan B

    Stan B Guest

    I create a popup window by calling window.showModalDialog

    Popup window has Ok button with this code attached:

    ===
    string Script = "<script language=JavaScript>" +
    "{" +
    "window.close();" +
    "}" +
    "</script>";

    if (!ClientScript.IsClientScriptBlockRegistered("CloseScript"))
    ClientScript.RegisterClientScriptBlock (Page.GetType(),
    "CloseScript", Script);

    ===

    When Ok button is clilcked, the window is flickering but does not close.

    1. If window.showModalDialog is replaced with window.open, everything works
    fine.

    2. Similar code worked fine on 1.1 framework

    3. There is a workaround to set window.opener to some value. I tried that -
    didn't work

    Thanks,

    -Stan
     
    Stan B, Oct 16, 2006
    #1
    1. Advertising

  2. Stan,

    Would not it be easier to put the script straight to the <head> section of
    the aspx page, setup the button's onclick event and stop worrying about the
    script registration calls?

    --
    Eliyahu Goldin,
    Software Developer & Consultant
    Microsoft MVP [ASP.NET]


    "Stan B" <> wrote in message
    news:...
    >I create a popup window by calling window.showModalDialog
    >
    > Popup window has Ok button with this code attached:
    >
    > ===
    > string Script = "<script language=JavaScript>" +
    > "{" +
    > "window.close();" +
    > "}" +
    > "</script>";
    >
    > if (!ClientScript.IsClientScriptBlockRegistered("CloseScript"))
    > ClientScript.RegisterClientScriptBlock (Page.GetType(),
    > "CloseScript", Script);
    >
    > ===
    >
    > When Ok button is clilcked, the window is flickering but does not close.
    >
    > 1. If window.showModalDialog is replaced with window.open, everything
    > works fine.
    >
    > 2. Similar code worked fine on 1.1 framework
    >
    > 3. There is a workaround to set window.opener to some value. I tried
    > that - didn't work
    >
    > Thanks,
    >
    > -Stan
    >
     
    Eliyahu Goldin, Oct 16, 2006
    #2
    1. Advertising

  3. Stan B

    Stan B Guest

    Eliyahu, it would. But how can I solve my problem of window not being
    closed?

    "Eliyahu Goldin" <> wrote in
    message news:u$MR$...
    > Stan,
    >
    > Would not it be easier to put the script straight to the <head> section of
    > the aspx page, setup the button's onclick event and stop worrying about
    > the script registration calls?
    >
    > --
    > Eliyahu Goldin,
    > Software Developer & Consultant
    > Microsoft MVP [ASP.NET]
    >
    >
    > "Stan B" <> wrote in message
    > news:...
    >>I create a popup window by calling window.showModalDialog
    >>
    >> Popup window has Ok button with this code attached:
    >>
    >> ===
    >> string Script = "<script language=JavaScript>" +
    >> "{" +
    >> "window.close();" +
    >> "}" +
    >> "</script>";
    >>
    >> if (!ClientScript.IsClientScriptBlockRegistered("CloseScript"))
    >> ClientScript.RegisterClientScriptBlock (Page.GetType(),
    >> "CloseScript", Script);
    >>
    >> ===
    >>
    >> When Ok button is clilcked, the window is flickering but does not close.
    >>
    >> 1. If window.showModalDialog is replaced with window.open, everything
    >> works fine.
    >>
    >> 2. Similar code worked fine on 1.1 framework
    >>
    >> 3. There is a workaround to set window.opener to some value. I tried
    >> that - didn't work
    >>
    >> Thanks,
    >>
    >> -Stan
    >>

    >
    >
     
    Stan B, Oct 16, 2006
    #3
  4. when a modal dialog box postbacks, it does not postbck to the same window,
    so the client script you generate is not running in the popup window. to
    postback to the same window, have a frameset page host the dialog page. then
    i believe you will need to close the parents window.

    -- bruce (sqlwork.com)


    "Stan B" <> wrote in message
    news:...
    >I create a popup window by calling window.showModalDialog
    >
    > Popup window has Ok button with this code attached:
    >
    > ===
    > string Script = "<script language=JavaScript>" +
    > "{" +
    > "window.close();" +
    > "}" +
    > "</script>";
    >
    > if (!ClientScript.IsClientScriptBlockRegistered("CloseScript"))
    > ClientScript.RegisterClientScriptBlock (Page.GetType(),
    > "CloseScript", Script);
    >
    > ===
    >
    > When Ok button is clilcked, the window is flickering but does not close.
    >
    > 1. If window.showModalDialog is replaced with window.open, everything
    > works fine.
    >
    > 2. Similar code worked fine on 1.1 framework
    >
    > 3. There is a workaround to set window.opener to some value. I tried
    > that - didn't work
    >
    > Thanks,
    >
    > -Stan
    >
     
    bruce barker \(sqlwork.com\), Oct 16, 2006
    #4
  5. Does
    <input type="button" value="Ok" onclick="window.close();"/>
    work?
    --
    Eliyahu Goldin,
    Software Developer & Consultant
    Microsoft MVP [ASP.NET]


    "Stan B" <> wrote in message
    news:...
    > Eliyahu, it would. But how can I solve my problem of window not being
    > closed?
    >
    > "Eliyahu Goldin" <> wrote in
    > message news:u$MR$...
    >> Stan,
    >>
    >> Would not it be easier to put the script straight to the <head> section
    >> of the aspx page, setup the button's onclick event and stop worrying
    >> about the script registration calls?
    >>
    >> --
    >> Eliyahu Goldin,
    >> Software Developer & Consultant
    >> Microsoft MVP [ASP.NET]
    >>
    >>
    >> "Stan B" <> wrote in message
    >> news:...
    >>>I create a popup window by calling window.showModalDialog
    >>>
    >>> Popup window has Ok button with this code attached:
    >>>
    >>> ===
    >>> string Script = "<script language=JavaScript>" +
    >>> "{" +
    >>> "window.close();" +
    >>> "}" +
    >>> "</script>";
    >>>
    >>> if (!ClientScript.IsClientScriptBlockRegistered("CloseScript"))
    >>> ClientScript.RegisterClientScriptBlock (Page.GetType(),
    >>> "CloseScript", Script);
    >>>
    >>> ===
    >>>
    >>> When Ok button is clilcked, the window is flickering but does not close.
    >>>
    >>> 1. If window.showModalDialog is replaced with window.open, everything
    >>> works fine.
    >>>
    >>> 2. Similar code worked fine on 1.1 framework
    >>>
    >>> 3. There is a workaround to set window.opener to some value. I tried
    >>> that - didn't work
    >>>
    >>> Thanks,
    >>>
    >>> -Stan
    >>>

    >>
    >>

    >
    >
     
    Eliyahu Goldin, Oct 16, 2006
    #5
  6. Stan B

    Stan B Guest

    It does post back to the same window. I can set a breakpoint there

    "bruce barker (sqlwork.com)" <> wrote
    in message news:%...
    > when a modal dialog box postbacks, it does not postbck to the same window,
    > so the client script you generate is not running in the popup window. to
    > postback to the same window, have a frameset page host the dialog page.
    > then i believe you will need to close the parents window.
    >
    > -- bruce (sqlwork.com)
    >
    >
    > "Stan B" <> wrote in message
    > news:...
    >>I create a popup window by calling window.showModalDialog
    >>
    >> Popup window has Ok button with this code attached:
    >>
    >> ===
    >> string Script = "<script language=JavaScript>" +
    >> "{" +
    >> "window.close();" +
    >> "}" +
    >> "</script>";
    >>
    >> if (!ClientScript.IsClientScriptBlockRegistered("CloseScript"))
    >> ClientScript.RegisterClientScriptBlock (Page.GetType(),
    >> "CloseScript", Script);
    >>
    >> ===
    >>
    >> When Ok button is clilcked, the window is flickering but does not close.
    >>
    >> 1. If window.showModalDialog is replaced with window.open, everything
    >> works fine.
    >>
    >> 2. Similar code worked fine on 1.1 framework
    >>
    >> 3. There is a workaround to set window.opener to some value. I tried
    >> that - didn't work
    >>
    >> Thanks,
    >>
    >> -Stan
    >>

    >
    >
     
    Stan B, Oct 16, 2006
    #6
  7. Stan B

    Stan B Guest

    Yes, it does!
    "Eliyahu Goldin" <> wrote in
    message news:...
    > Does
    > <input type="button" value="Ok" onclick="window.close();"/>
    > work?
    > --
    > Eliyahu Goldin,
    > Software Developer & Consultant
    > Microsoft MVP [ASP.NET]
    >
    >
    > "Stan B" <> wrote in message
    > news:...
    >> Eliyahu, it would. But how can I solve my problem of window not being
    >> closed?
    >>
    >> "Eliyahu Goldin" <> wrote in
    >> message news:u$MR$...
    >>> Stan,
    >>>
    >>> Would not it be easier to put the script straight to the <head> section
    >>> of the aspx page, setup the button's onclick event and stop worrying
    >>> about the script registration calls?
    >>>
    >>> --
    >>> Eliyahu Goldin,
    >>> Software Developer & Consultant
    >>> Microsoft MVP [ASP.NET]
    >>>
    >>>
    >>> "Stan B" <> wrote in message
    >>> news:...
    >>>>I create a popup window by calling window.showModalDialog
    >>>>
    >>>> Popup window has Ok button with this code attached:
    >>>>
    >>>> ===
    >>>> string Script = "<script language=JavaScript>" +
    >>>> "{" +
    >>>> "window.close();" +
    >>>> "}" +
    >>>> "</script>";
    >>>>
    >>>> if (!ClientScript.IsClientScriptBlockRegistered("CloseScript"))
    >>>> ClientScript.RegisterClientScriptBlock (Page.GetType(),
    >>>> "CloseScript", Script);
    >>>>
    >>>> ===
    >>>>
    >>>> When Ok button is clilcked, the window is flickering but does not
    >>>> close.
    >>>>
    >>>> 1. If window.showModalDialog is replaced with window.open, everything
    >>>> works fine.
    >>>>
    >>>> 2. Similar code worked fine on 1.1 framework
    >>>>
    >>>> 3. There is a workaround to set window.opener to some value. I tried
    >>>> that - didn't work
    >>>>
    >>>> Thanks,
    >>>>
    >>>> -Stan
    >>>>
    >>>
    >>>

    >>
    >>

    >
    >
     
    Stan B, Oct 16, 2006
    #7
  8. Stan B

    Stan B Guest

    It does work, but I still need close the window from the server because I am
    saving user selection
    in session.

    So, when the script is injected by RegisterClientScriptBlock AND the window
    is opened
    via showModalDialog, it does not close.

    Is there a workaround for this?




    "Eliyahu Goldin" <> wrote in
    message news:...
    > Does
    > <input type="button" value="Ok" onclick="window.close();"/>
    > work?
    > --
    > Eliyahu Goldin,
    > Software Developer & Consultant
    > Microsoft MVP [ASP.NET]
    >
    >
    > "Stan B" <> wrote in message
    > news:...
    >> Eliyahu, it would. But how can I solve my problem of window not being
    >> closed?
    >>
    >> "Eliyahu Goldin" <> wrote in
    >> message news:u$MR$...
    >>> Stan,
    >>>
    >>> Would not it be easier to put the script straight to the <head> section
    >>> of the aspx page, setup the button's onclick event and stop worrying
    >>> about the script registration calls?
    >>>
    >>> --
    >>> Eliyahu Goldin,
    >>> Software Developer & Consultant
    >>> Microsoft MVP [ASP.NET]
    >>>
    >>>
    >>> "Stan B" <> wrote in message
    >>> news:...
    >>>>I create a popup window by calling window.showModalDialog
    >>>>
    >>>> Popup window has Ok button with this code attached:
    >>>>
    >>>> ===
    >>>> string Script = "<script language=JavaScript>" +
    >>>> "{" +
    >>>> "window.close();" +
    >>>> "}" +
    >>>> "</script>";
    >>>>
    >>>> if (!ClientScript.IsClientScriptBlockRegistered("CloseScript"))
    >>>> ClientScript.RegisterClientScriptBlock (Page.GetType(),
    >>>> "CloseScript", Script);
    >>>>
    >>>> ===
    >>>>
    >>>> When Ok button is clilcked, the window is flickering but does not
    >>>> close.
    >>>>
    >>>> 1. If window.showModalDialog is replaced with window.open, everything
    >>>> works fine.
    >>>>
    >>>> 2. Similar code worked fine on 1.1 framework
    >>>>
    >>>> 3. There is a workaround to set window.opener to some value. I tried
    >>>> that - didn't work
    >>>>
    >>>> Thanks,
    >>>>
    >>>> -Stan
    >>>>
    >>>
    >>>

    >>
    >>

    >
    >
     
    Stan B, Oct 17, 2006
    #8
  9. I never liked the idea of script injection from the server. Instead of
    passing javascript code from the server, almost always (there are
    exceptions!) you can leave all scripts in the client code and pass from the
    server a message instructing the client what to do. You can have a hidden
    input control for passing this sort of messages:

    <head>
    <script>
    function checkAction(){
    switch(form1.inhAction.value){
    case "CLOSE":
    window.close();
    break;
    .....
    }
    form1.inhAction.value="";
    }
    </script>
    </head>
    <body onload="checkAction()">
    <form id="form1" ...
    ....
    <input type="hidden" runate="server" id="inhAction" />


    --
    Eliyahu Goldin,
    Software Developer & Consultant
    Microsoft MVP [ASP.NET]


    "Stan B" <> wrote in message
    news:...
    > It does work, but I still need close the window from the server because I
    > am saving user selection
    > in session.
    >
    > So, when the script is injected by RegisterClientScriptBlock AND the
    > window is opened
    > via showModalDialog, it does not close.
    >
    > Is there a workaround for this?
    >
    >
    >
    >
    > "Eliyahu Goldin" <> wrote in
    > message news:...
    >> Does
    >> <input type="button" value="Ok" onclick="window.close();"/>
    >> work?
    >> --
    >> Eliyahu Goldin,
    >> Software Developer & Consultant
    >> Microsoft MVP [ASP.NET]
    >>
    >>
    >> "Stan B" <> wrote in message
    >> news:...
    >>> Eliyahu, it would. But how can I solve my problem of window not being
    >>> closed?
    >>>
    >>> "Eliyahu Goldin" <> wrote in
    >>> message news:u$MR$...
    >>>> Stan,
    >>>>
    >>>> Would not it be easier to put the script straight to the <head> section
    >>>> of the aspx page, setup the button's onclick event and stop worrying
    >>>> about the script registration calls?
    >>>>
    >>>> --
    >>>> Eliyahu Goldin,
    >>>> Software Developer & Consultant
    >>>> Microsoft MVP [ASP.NET]
    >>>>
    >>>>
    >>>> "Stan B" <> wrote in message
    >>>> news:...
    >>>>>I create a popup window by calling window.showModalDialog
    >>>>>
    >>>>> Popup window has Ok button with this code attached:
    >>>>>
    >>>>> ===
    >>>>> string Script = "<script language=JavaScript>" +
    >>>>> "{" +
    >>>>> "window.close();" +
    >>>>> "}" +
    >>>>> "</script>";
    >>>>>
    >>>>> if (!ClientScript.IsClientScriptBlockRegistered("CloseScript"))
    >>>>> ClientScript.RegisterClientScriptBlock (Page.GetType(),
    >>>>> "CloseScript", Script);
    >>>>>
    >>>>> ===
    >>>>>
    >>>>> When Ok button is clilcked, the window is flickering but does not
    >>>>> close.
    >>>>>
    >>>>> 1. If window.showModalDialog is replaced with window.open, everything
    >>>>> works fine.
    >>>>>
    >>>>> 2. Similar code worked fine on 1.1 framework
    >>>>>
    >>>>> 3. There is a workaround to set window.opener to some value. I tried
    >>>>> that - didn't work
    >>>>>
    >>>>> Thanks,
    >>>>>
    >>>>> -Stan
    >>>>>
    >>>>
    >>>>
    >>>
    >>>

    >>
    >>

    >
    >
     
    Eliyahu Goldin, Oct 17, 2006
    #9
  10. Stan B

    Stan B Guest

    It still does not close the form!

    <script language=javascript>
    function checkAction()
    {
    if (form1.inhAction.value == "C")
    {
    alert ("closing the form");
    window.close();
    }
    form1.inhAction.value = "";
    }
    </script>

    I set inhAction = "C" on the server and see "closing the form" popup, but
    the form remains open...


    "Eliyahu Goldin" <> wrote in
    message news:u%...
    >I never liked the idea of script injection from the server. Instead of
    >passing javascript code from the server, almost always (there are
    >exceptions!) you can leave all scripts in the client code and pass from the
    >server a message instructing the client what to do. You can have a hidden
    >input control for passing this sort of messages:
    >
    > <head>
    > <script>
    > function checkAction(){
    > switch(form1.inhAction.value){
    > case "CLOSE":
    > window.close();
    > break;
    > .....
    > }
    > form1.inhAction.value="";
    > }
    > </script>
    > </head>
    > <body onload="checkAction()">
    > <form id="form1" ...
    > ...
    > <input type="hidden" runate="server" id="inhAction" />
    >
    >
    > --
    > Eliyahu Goldin,
    > Software Developer & Consultant
    > Microsoft MVP [ASP.NET]
    >
    >
    > "Stan B" <> wrote in message
    > news:...
    >> It does work, but I still need close the window from the server because I
    >> am saving user selection
    >> in session.
    >>
    >> So, when the script is injected by RegisterClientScriptBlock AND the
    >> window is opened
    >> via showModalDialog, it does not close.
    >>
    >> Is there a workaround for this?
    >>
    >>
    >>
    >>
    >> "Eliyahu Goldin" <> wrote in
    >> message news:...
    >>> Does
    >>> <input type="button" value="Ok" onclick="window.close();"/>
    >>> work?
    >>> --
    >>> Eliyahu Goldin,
    >>> Software Developer & Consultant
    >>> Microsoft MVP [ASP.NET]
    >>>
    >>>
    >>> "Stan B" <> wrote in message
    >>> news:...
    >>>> Eliyahu, it would. But how can I solve my problem of window not being
    >>>> closed?
    >>>>
    >>>> "Eliyahu Goldin" <> wrote in
    >>>> message news:u$MR$...
    >>>>> Stan,
    >>>>>
    >>>>> Would not it be easier to put the script straight to the <head>
    >>>>> section of the aspx page, setup the button's onclick event and stop
    >>>>> worrying about the script registration calls?
    >>>>>
    >>>>> --
    >>>>> Eliyahu Goldin,
    >>>>> Software Developer & Consultant
    >>>>> Microsoft MVP [ASP.NET]
    >>>>>
    >>>>>
    >>>>> "Stan B" <> wrote in message
    >>>>> news:...
    >>>>>>I create a popup window by calling window.showModalDialog
    >>>>>>
    >>>>>> Popup window has Ok button with this code attached:
    >>>>>>
    >>>>>> ===
    >>>>>> string Script = "<script language=JavaScript>" +
    >>>>>> "{" +
    >>>>>> "window.close();" +
    >>>>>> "}" +
    >>>>>> "</script>";
    >>>>>>
    >>>>>> if
    >>>>>> (!ClientScript.IsClientScriptBlockRegistered("CloseScript"))
    >>>>>> ClientScript.RegisterClientScriptBlock (Page.GetType(),
    >>>>>> "CloseScript", Script);
    >>>>>>
    >>>>>> ===
    >>>>>>
    >>>>>> When Ok button is clilcked, the window is flickering but does not
    >>>>>> close.
    >>>>>>
    >>>>>> 1. If window.showModalDialog is replaced with window.open, everything
    >>>>>> works fine.
    >>>>>>
    >>>>>> 2. Similar code worked fine on 1.1 framework
    >>>>>>
    >>>>>> 3. There is a workaround to set window.opener to some value. I tried
    >>>>>> that - didn't work
    >>>>>>
    >>>>>> Thanks,
    >>>>>>
    >>>>>> -Stan
    >>>>>>
    >>>>>
    >>>>>
    >>>>
    >>>>
    >>>
    >>>

    >>
    >>

    >
    >
     
    Stan B, Oct 17, 2006
    #10
    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. Simon Storr
    Replies:
    5
    Views:
    39,459
  2. kurt sune
    Replies:
    2
    Views:
    7,462
    imransyed63
    Aug 19, 2008
  3. Iñaki Baz Castillo
    Replies:
    7
    Views:
    869
    Iñaki Baz Castillo
    Jan 12, 2010
  4. Jonathan
    Replies:
    0
    Views:
    194
    Jonathan
    Jul 19, 2004
  5. Shang Wenbin

    close current window using window.close()

    Shang Wenbin, Sep 1, 2005, in forum: Javascript
    Replies:
    10
    Views:
    378
    Gérard Talbot
    Sep 2, 2005
Loading...

Share This Page