< %@ Page Language="C#" AutoEventWireup="true" CodeFile="DialogDemo.aspx.cs" Inherits="DialogDemo" % > <!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>Dialog Demo</title> <script language="javascript" type="text/javascript"> // Launches a simple modal dialog and displays the value returned. function ShowPopup() { retVal = window.showModalDialog("DialogContent.aspx", "wDialog", "dialogWidth:400px;dialogHeight:200px;center:yes;"); document.getElementById("txtReturnedValue").innerText = retVal; } </script> </head> <body> <form id="form1" runat="server"> <div> <p>This demo shows how to use dialogs in ASP.NET</p> </div> <div> <input id="Button1" type="button" value="Launch Dialog..." onclick="ShowPopup();"/> <br /> <br /> You entered: <asp:TextBox ID="txtReturnedValue" runat="server"></asp:TextBox></div> </form> </body> </html>2) Next create the dialog. Note the use of
<base target="_self" />
If the page does a postback, the browser wants to launch yet another window! An alternate technique is to use an IFRAME in one web page that references the actual dialog content. For this demo, though, the base target="_self" works good enough.< %@ Page Language="C#" AutoEventWireup="true" CodeFile="DialogContent.aspx.cs" Inherits="DialogContent" % > <!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>Simple Dialog</title> <base target="_self" /> <script language="javascript" type="text/javascript"> // Closes the simple modal dialog and passes the entered value back to the parent web page. function ClosePopup() { window.returnValue = document.getElementById("Text1").value; window.close(); } </script> </head> <body> <form id="form1" runat="server"> <table style="width: 100%"> <tr> <td style="text-align: right;">Enter Your Name:</td> <td style="text-align: left;"><input id="Text1" type="text" size="30" /></td> </tr> <tr> <td></td> <td> <input id="Button1" type="button" value="Submit" onclick="ClosePopup();"/></td> </tr> </table> </form> </body> </html>