Close Window that opens with window.showModalDialog

Last post 01-11-2008 12:36 AM by thuhue. 7 replies.

Sort Posts:

  • Close Window that opens with window.showModalDialog

    05-24-2006, 9:12 AM
    • Member
      357 point Member
    • ChrisDev
    • Member since 03-22-2006, 7:43 AM
    • Posts 114

    Hi,

    How can I close a window that open with the java script below ?

    window.showModalDialog('Report.aspx', '','dialogHeight=800px;dialogWidth=800px');

    The Window.Close(); does not closes it, but opens one more window (same as the modal one)

    Thanks a lot.

     

  • Re: Close Window that opens with window.showModalDialog

    05-24-2006, 10:43 AM
    • Contributor
      2,509 point Contributor
    • chunshahab
    • Member since 07-07-2003, 2:49 PM
    • USA
    • Posts 501

    window.close(); should work.

    Where did you put window.close()? Here is a simple sample:

    One my mai page I have a linek that opens the modal dialog:

    <a href="JavaScript:window.showModalDialog('Default.aspx', '','dialogHeight=800px;dialogWidth=800px');">Open</a>

    One my Default.aspx page, I have a OK button that close the window (I used a HTML button):

    <input type="button" name="btnOk" value="OK" onclick="JavaScript: window.close();" />

    Hope it helps.

     

    Help Whenever You Can
    Live Without Regret
  • Re: Close Window that opens with window.showModalDialog

    05-25-2006, 1:25 AM
    • Member
      357 point Member
    • ChrisDev
    • Member since 03-22-2006, 7:43 AM
    • Posts 114

    I have the following:

    on Test.aspx page

    <asp:Button ID="Button1" runat="server" Text="Button" OnClientClick = "open_window();" />&nbsp;

    <script type="text/javascript">

    function open_window()

    {window.showModalDialog(

    'test2.aspx', '','dialogHeight=800px;dialogWidth=800px');}

    </script>

    on Test2.aspx page

    <asp:Button ID="Button2" runat="server" Text="Button" OnclientClick = "close_window();" />

    <script type="text/javascript">

    function close_window()

    {window.close();}

    </script>

    When I click on close button, modal window closes, but then a normal window of Test.aspx opens.

    When I changed "window.showModalDialog" to "window.open", "window.close" seemed to work, but "window.open" does not open a modal window.

  • Re: Close Window that opens with window.showModalDialog

    05-25-2006, 1:52 AM
    • Member
      746 point Member
    • mansoorl
    • Member since 12-23-2004, 8:01 PM
    • Toronto, Canada
    • Posts 145

    All you need to do is add

    <base target="_self"> inside the head tag of the page you are calling as modal and you should be good to go.

    Cheers,

    Mansoor Lakhani
    Senior .NET consultant
    DOT Specialists - Your one stop IT solutions company, specializing in software offshoring services

  • Re: Close Window that opens with window.showModalDialog

    05-25-2006, 6:03 AM
    • Member
      357 point Member
    • ChrisDev
    • Member since 03-22-2006, 7:43 AM
    • Posts 114

    Thanks a lot, Mansoor for your message.

    I am using ASP.NET 2.0. Where shall I find <head> tag ? In the source of my aspx, I could see the page declation

    <%

    @ Page

    and

    <

    asp:Content

     

  • Re: Close Window that opens with window.showModalDialog

    05-26-2006, 1:17 AM
    • Member
      746 point Member
    • mansoorl
    • Member since 12-23-2004, 8:01 PM
    • Toronto, Canada
    • Posts 145

    Looks like you are calling the content page as your modal dialoag.  Is that is the case, you will need to put the tag in your master page.

    Remember the <base target=_self> goes inside the head tag of the window that is being displayed as modal

     

    <head>

    <meta tags>

    <base target="_self'>

    </head>

     

    Cheers,

  • Re: Close Window that opens with window.showModalDialog

    06-19-2006, 4:37 AM
    • Member
      357 point Member
    • ChrisDev
    • Member since 03-22-2006, 7:43 AM
    • Posts 114

    Thanks a lot Mansoorl.

    Yes, that was the case. It works fine now!!

  • Re: Close Window that opens with window.showModalDialog

    01-11-2008, 12:36 AM
    • Star
      7,580 point Star
    • thuhue
    • Member since 09-18-2003, 9:54 AM
    • Posts 2,236

    After reading the previous posts, I have a question about this:

    <asp:Button ID="Button2" runat="server" Text="Button" OnclientClick = "close_window();" />

    <script type="text/javascript">

    function close_window()

    {window.close();}

    </script>  

    As Button2 is clicked,  can some code behind (say a stored proc query) be run before close_window()? Please advise how. Thanks.

     

     

     

     

    Please mark the post(s) that have helped you as "Answer"
Page 1 of 1 (8 items)