Unable to Close Popup window using ASP.Net

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • GrantS

    Unable to Close Popup window using ASP.Net

    I am having a problem closing a popup window opened modally. When I
    try to close the window (when the user hits save button and the data
    has been processed), the Popup window opens as a full screen as a new
    window. The original window plus the Modally opened Pop remain in a
    separate window.

    What I want to do is close the popup and return to the original window
    with its view state maintained.

    The control use to fire the popup window and the one to save the
    changes need to be a web server control.
    The popup window needs to be modal.


    *************** *************** *************** *************** ***************
    The code I am using open the window with this control is:

    private void butChangeOrder_ Click(object sender, System.EventArg s e)
    {
    if (!IsClientScrip tBlockRegistere d("OpenPopup" ))
    {
    RegisterClientS criptBlock("Ope nPopup", "<script
    language=\"java script\">window .showModalDialo g('PopUpSortOrd er.aspx',null,' font-size:10px;dialo gWidth:43em;dia logHeight:40em,
    toolbar=0,locat ion=0,directori es=0,status=no, menuBar=1,scrol lBars=no,resiza ble=no')</script>");
    }
    }

    *************** *************** *************** *************** ***************

    The code that I am using to close the Popup window is:

    private void butSaveOrder_Cl ick(object sender, System.EventArg s e)
    {
    DataSavings dtSave = new CMSDataViewer.U tilities.DataSa vings ();
    dtSave.SaveSort Orders(false,Hi ddenIds );

    if( !Page.IsClientS criptBlockRegis tered ("ClosePopUp "))
    {
    RegisterClientS criptBlock("Clo sePopUp", "<script
    language=\"java script\">functi on
    CloseMe(){windo w.close();windo w.history.back( ); };</script>");
    }
    butSaveOrder.At tributes.Add("o nclick", "ClosePopUp()") ;
    }


    *************** *************** *************** *************** ***************
    Hopefully someone has a solution in this regard.

    Cheers.

    GrantS
  • Patrik Löwendahl

    #2
    Re: Unable to Close Popup window using ASP.Net

    Try to write out the script directly to the page after the save of data.

    <code>
    private void butSaveOrder_Cl ick(object sender, System.EventArg s e)
    {
    DataSavings dtSave = new CMSDataViewer.U tilities.DataSa vings ();
    dtSave.SaveSort Orders(false,Hi ddenIds );
    Response.Write( "<script language=\"Java script\">window .opener =
    self;window.clo se();</script>");
    Response.End();
    }
    </code>

    The window.opener = self statement is to bypass the annoying message box
    that IE throws at you when trying to close a window from javascript.

    --
    Patrik Löwendahl
    cshrp.net - " Elegant code by witty programmers "
    cornerstone.se - " IT Training for professionals "


    "GrantS" <sutcliffe_gran t@hotmail.com> wrote in message
    news:6963940b.0 310231308.60b89 80@posting.goog le.com...[color=blue]
    > I am having a problem closing a popup window opened modally. When I
    > try to close the window (when the user hits save button and the data
    > has been processed), the Popup window opens as a full screen as a new
    > window. The original window plus the Modally opened Pop remain in a
    > separate window.
    >
    > What I want to do is close the popup and return to the original window
    > with its view state maintained.
    >
    > The control use to fire the popup window and the one to save the
    > changes need to be a web server control.
    > The popup window needs to be modal.
    >
    >
    >[/color]
    *************** *************** *************** *************** ***************[color=blue]
    > The code I am using open the window with this control is:
    >
    > private void butChangeOrder_ Click(object sender, System.EventArg s e)
    > {
    > if (!IsClientScrip tBlockRegistere d("OpenPopup" ))
    > {
    > RegisterClientS criptBlock("Ope nPopup", "<script
    >[/color]
    language=\"java script\">window .showModalDialo g('PopUpSortOrd er.aspx',null,' f
    ont-size:10px;dialo gWidth:43em;dia logHeight:40em,[color=blue]
    >[/color]
    toolbar=0,locat ion=0,directori es=0,status=no, menuBar=1,scrol lBars=no,resiza b
    le=no')</script>");[color=blue]
    > }
    > }
    >
    >[/color]
    *************** *************** *************** *************** ***************[color=blue]
    >
    > The code that I am using to close the Popup window is:
    >
    > private void butSaveOrder_Cl ick(object sender, System.EventArg s e)
    > {
    > DataSavings dtSave = new CMSDataViewer.U tilities.DataSa vings ();
    > dtSave.SaveSort Orders(false,Hi ddenIds );
    >
    > if( !Page.IsClientS criptBlockRegis tered ("ClosePopUp "))
    > {
    > RegisterClientS criptBlock("Clo sePopUp", "<script
    > language=\"java script\">functi on
    > CloseMe(){windo w.close();windo w.history.back( ); };</script>");
    > }
    > butSaveOrder.At tributes.Add("o nclick", "ClosePopUp()") ;
    > }
    >
    >
    >[/color]
    *************** *************** *************** *************** ***************[color=blue]
    > Hopefully someone has a solution in this regard.
    >
    > Cheers.
    >
    > GrantS[/color]


    Comment

    • Juan Gabriel Del Cid

      #3
      Re: Unable to Close Popup window using ASP.Net

      > if( !Page.IsClientS criptBlockRegis tered ("ClosePopUp "))[color=blue]
      > {
      > RegisterClientS criptBlock("Clo sePopUp", "<script
      > language=\"java script\">functi on
      > CloseMe(){windo w.close();windo w.history.back( ); };</script>");
      > }
      > butSaveOrder.At tributes.Add("o nclick", "ClosePopUp()") ;
      > }[/color]

      Well, the button's onclick event should be wired to CloseMe(), not to
      ClosePopUp (that's just the scripts key).

      Another thing is that you call window.close() and then
      window.history. back()... doesn't this mean you are trying to naviagate
      backwards on a closed window?

      Hope that helps,
      -JG


      Comment

      • N

        #4
        Unable to Close Popup window using ASP.Net

        You can try this

        set <base target="_self"> for the popup window page and
        then on click of the save button, save the data and then
        do
        RegisterStartup Script("winclos e","<script>win dow.close
        ();</script>");.

        Hope this helps,
        N
        [color=blue]
        >-----Original Message-----
        >I am having a problem closing a popup window opened[/color]
        modally. When I[color=blue]
        >try to close the window (when the user hits save button[/color]
        and the data[color=blue]
        >has been processed), the Popup window opens as a full[/color]
        screen as a new[color=blue]
        >window. The original window plus the Modally opened Pop[/color]
        remain in a[color=blue]
        >separate window.
        >
        >What I want to do is close the popup and return to the[/color]
        original window[color=blue]
        >with its view state maintained.
        >
        >The control use to fire the popup window and the one to[/color]
        save the[color=blue]
        >changes need to be a web server control.
        >The popup window needs to be modal.
        >
        >
        >************** *************** *************** **************[/color]
        *************** **[color=blue]
        >The code I am using open the window with this control is:
        >
        >private void butChangeOrder_ Click(object sender,[/color]
        System.EventArg s e)[color=blue]
        > {
        > if (!IsClientScrip tBlockRegistere d[/color]
        ("OpenPopup" ))[color=blue]
        > {[/color]
        [color=blue]
        > RegisterClientS criptBlock[/color]
        ("OpenPopup" , "<script[color=blue]
        >language=\"jav ascript\">windo w.showModalDial og[/color]
        ('PopUpSortOrde r.aspx',null,'f ont-
        size:10px;dialo gWidth:43em;dia logHeight:40em,[color=blue]
        >toolbar=0,loca tion=0,director ies=0,status=no ,menuBar=1,scr[/color]
        ollBars=no,resi zable=no')</script>");[color=blue]
        > }
        > }
        >
        >************** *************** *************** **************[/color]
        *************** **[color=blue]
        >
        >The code that I am using to close the Popup window is:
        >
        >private void butSaveOrder_Cl ick(object sender,[/color]
        System.EventArg s e)[color=blue]
        > {
        > DataSavings dtSave = new[/color]
        CMSDataViewer.U tilities.DataSa vings ();[color=blue]
        > dtSave.SaveSort Orders[/color]
        (false,HiddenId s );[color=blue]
        >
        > if( ![/color]
        Page.IsClientSc riptBlockRegist ered ("ClosePopUp "))[color=blue]
        > {
        > RegisterClientS criptBlock[/color]
        ("ClosePopUp ", "<script[color=blue]
        >language=\"jav ascript\">funct ion
        >CloseMe(){wind ow.close();wind ow.history.back[/color]
        (); };</script>");[color=blue]
        > }
        > butSaveOrder.At tributes.Add[/color]
        ("onclick", "ClosePopUp()") ;[color=blue]
        > }
        >
        >
        >************** *************** *************** **************[/color]
        *************** **[color=blue]
        >Hopefully someone has a solution in this regard.
        >
        >Cheers.
        >
        >GrantS
        >.
        >[/color]

        Comment

        • GrantS

          #5
          Re: Unable to Close Popup window using ASP.Net

          "Patrik Löwendahl" <patrik.lowenda hl@csharpsweden .com> wrote in message news:<ukrcKWcmD HA.1800@TK2MSFT NGP10.phx.gbl>. ..[color=blue]
          > Try to write out the script directly to the page after the save of data.
          >
          > <code>
          > private void butSaveOrder_Cl ick(object sender, System.EventArg s e)
          > {
          > DataSavings dtSave = new CMSDataViewer.U tilities.DataSa vings ();
          > dtSave.SaveSort Orders(false,Hi ddenIds );
          > Response.Write( "<script language=\"Java script\">window .opener =
          > self;window.clo se();</script>");
          > Response.End();
          > }
          > </code>
          >
          > The window.opener = self statement is to bypass the annoying message box
          > that IE throws at you when trying to close a window from javascript.
          >
          > --
          > Patrik Löwendahl
          > cshrp.net - " Elegant code by witty programmers "
          > cornerstone.se - " IT Training for professionals "
          >
          >
          > "GrantS" <sutcliffe_gran t@hotmail.com> wrote in message
          > news:6963940b.0 310231308.60b89 80@posting.goog le.com...[color=green]
          > > I am having a problem closing a popup window opened modally. When I
          > > try to close the window (when the user hits save button and the data
          > > has been processed), the Popup window opens as a full screen as a new
          > > window. The original window plus the Modally opened Pop remain in a
          > > separate window.
          > >
          > > What I want to do is close the popup and return to the original window
          > > with its view state maintained.
          > >
          > > The control use to fire the popup window and the one to save the
          > > changes need to be a web server control.
          > > The popup window needs to be modal.
          > >
          > >
          > >[/color]
          > *************** *************** *************** *************** ***************[color=green]
          > > The code I am using open the window with this control is:
          > >
          > > private void butChangeOrder_ Click(object sender, System.EventArg s e)
          > > {
          > > if (!IsClientScrip tBlockRegistere d("OpenPopup" ))
          > > {
          > > RegisterClientS criptBlock("Ope nPopup", "<script
          > >[/color]
          > language=\"java script\">window .showModalDialo g('PopUpSortOrd er.aspx',null,' f
          > ont-size:10px;dialo gWidth:43em;dia logHeight:40em,[color=green]
          > >[/color]
          > toolbar=0,locat ion=0,directori es=0,status=no, menuBar=1,scrol lBars=no,resiza b
          > le=no')</script>");[color=green]
          > > }
          > > }
          > >
          > >[/color]
          > *************** *************** *************** *************** ***************[color=green]
          > >
          > > The code that I am using to close the Popup window is:
          > >
          > > private void butSaveOrder_Cl ick(object sender, System.EventArg s e)
          > > {
          > > DataSavings dtSave = new CMSDataViewer.U tilities.DataSa vings ();
          > > dtSave.SaveSort Orders(false,Hi ddenIds );
          > >
          > > if( !Page.IsClientS criptBlockRegis tered ("ClosePopUp "))
          > > {
          > > RegisterClientS criptBlock("Clo sePopUp", "<script
          > > language=\"java script\">functi on
          > > CloseMe(){windo w.close();windo w.history.back( ); };</script>");
          > > }[/color]
          > butSaveOrder.At tributes.Add("o nclick", "ClosePopUp()") ;[color=green]
          > > }
          > >
          > >
          > >[/color]
          > *************** *************** *************** *************** ***************[color=green]
          > > Hopefully someone has a solution in this regard.
          > >
          > > Cheers.
          > >
          > > GrantS[/color][/color]

          Excellent! Thanks folks for the suggestions. I played with each of the
          suggestions and turns out the the suggestion by N does what exactly
          what I need. Bingo!
          Code below with the last line being the one for others to use in this
          situation.
          Patrick's suggestion helped in that it did not throw up the extra
          form, so I could have used it in the save and gotten rid of the close
          button. The user could still close using the control box.
          I played with the things Juan suggested but no go.

          *************** *************** *************** *************** *************** *************** *****

          private void butSaveOrder_Cl ick(object sender, System.EventArg s e)
          {
          DataSavings dtSave = new CMSDataViewer.U tilities.DataSa vings ();
          dtSave.SaveSort Orders(false,Hi ddenIds );


          /*
          //Suggestion 1 (Patrick): Saves but does not close PopUp(At least
          does not Open another window).
          Response.Write( "<script language=\"Java script\">window .opener
          = self;window.clo se();</script>");
          Response.End();


          //Suggestion 2 (JUan):My Original with Navigate before Close and the
          ClosePopUp used consistently
          if( !Page.IsClientS criptBlockRegis tered ("ClosePopUp "))
          {
          RegisterClientS criptBlock("Clo sePopUp", "<script
          language=\"java script\">functi on
          ClosePopUp(){wi ndow.history.ba ck();window.clo se(); };</script>");
          }
          butSaveOrder.At tributes.Add("o nclick", "ClosePopUp()") ;
          */



          //Suggestion 3 (N). This does the trick: - uses <base target="_self">
          in page header:
          RegisterStartup Script("winclos e","<script>win dow.close();</script>");

          }

          *************** *************** *************** *************** *************** *************** *****
          Thanks again. Grant

          Comment

          Working...