Modal Popup window opens new window when form posted

I am having trouble with modal dialog. 

I have a web page PopupTestParent.aspx and popup.aspx.

 When I click button on popupTestParent.aspx, it opens modal dialog as exptected, when I click button on Popup.aspx, and form gets posted, it opens a new window, instead of using same window as the form.  code for both pages is given below..

Any clue, how to get over this?

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="PopupTestParent.aspx.cs" Inherits="PopupTestParent" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
    <script type="text/javascript" type="text/javascript">
    function PopupWindow()
    {
        var popwin = window.showModalDialog("PopUp.aspx", document ,"resizable: yes; scrollbar: no; help: yes; status:yes; dialogHeight:580px; dialogWidth:510px");
    }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <input type="button" id="btnPopup" onclick="PopupWindow();" value="Popup Window" />
    </div>
    </form>
</body>
</html>

following is code for popup.aspx :

 

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Popup.aspx.cs" Inherits="Popup" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Button Text="submit" runat="server" ID="btnSubmit" OnClick="btnSubmit_Click" />
    </div>
    </form>
</body>
</html>

  and popup.aspx.cs :

    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        string strScript = "&lt;Script language='javascript'>window.close();</script>";
        ClientScript.RegisterStartupScript(this.GetType(), "StartScript", strScript);
    }

 

 

0
DotNetUserDeveloper
6/11/2008 10:13:14 PM
asp.net.client-side 24353 articles. 2 followers. Follow

2 Replies
4699 Views

Similar Articles

[PageSpeed] 5

In my experience, a modal dialog (IE) behaves as if it were "read only", i.e. you cannot change its contents after the initial load.

There are two ways to go about this:

Quick solution: Add <base target="_self"> to the head section of your popup.

Cumbersome solution: Place a "hidden" iframe (zero height) in your popup. Make sure your button targets the iframe when posting. You will still be allowed the close the window however. Also the iframe is able to update its parent through the DOM.

The second one is a nice approach if you have a more complex dialog in which you want a "AJAX kindof GUI" :-)


If this post was useful to you, please mark it as answer. Thank you!
0
johram
6/11/2008 10:28:58 PM

Thank you very much.  I tried first one, the simplest of all; solution.  <base target="_self">  works like a charm.

 

0
DotNetUserDeveloper
6/12/2008 2:36:55 PM
Reply: