Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to create a Dialog Web form in C#.Net?
Message
General information
Forum:
ASP.NET
Category:
Other
Miscellaneous
Thread ID:
01153202
Message ID:
01153645
Views:
17
Chad, there are several sources on the web that explain how to do this. Also, the technique used is going to depend on how you plan to use the dialog.

Here's just one approach:

1) Create a simple web page that will launch a modal dialog and return a value entered by the user:
< %@ 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>
Carl Olson, Jr.
CEO, Founder
Cerelogic, Inc.

www.cerelogic.com

"Applying rocket science to business."
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform