This is an article on how to set/get data on a modal dialog popup:
http://www.codeproject.com/aspnet/Modal_Dialog.asp
I'm trying to change the controls from HTML to ASP.NET but the code I wrote doesn't work. The reason I used JavaScript like in the article is I don't know of a way to refer to a pages controls from another page in my code.
Thanks.
parent.aspx
parent.aspx.csPHP Code:<%@ Page language="c#" Codebehind="parent.aspx.cs" AutoEventWireup="false" Inherits="Popup.parent" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>parent</title>
<script language="javascript">
function OpenChild()
{
var text1 = parent.parentText1.value;
var text2 = parent.parentText2.value;
var args = new Array(text1, text2);
var settings = "center:yes;resizable:no;dialogHeight:200px";
args = window.showModalDialog("child.aspx", args, settings);
if (args == null)
{
window.alert("No data change.")
}
else
{
parent.parentText1.value = args[0].toString();
parent.parentText2.value = args[1].toString();
}
}
</script>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="parent" method="post" runat="server">
<asp:TextBox id="parentText1" style="Z-INDEX: 101; LEFT: 32px; POSITION: absolute; TOP: 32px"
runat="server" Font-Size="Smaller" Font-Names="Arial" Height="20px" Width="159px"></asp:TextBox>
<asp:TextBox id="parentText2" style="Z-INDEX: 102; LEFT: 32px; POSITION: absolute; TOP: 64px"
runat="server" Font-Size="Smaller" Font-Names="Arial" Height="20px" Width="159px"></asp:TextBox>
<asp:Button id="parentButton1" style="Z-INDEX: 100; LEFT: 72px; POSITION: absolute; TOP: 104px"
runat="server" Font-Size="Smaller" Font-Names="Arial" Width="72px" Text="Enter Data"></asp:Button>
</form>
</body>
</HTML>
child.aspxCode:using System; using System.Collections; using System.ComponentModel; using System.Data; using System.Drawing; using System.Web; using System.Web.SessionState; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.HtmlControls; namespace Popup { /// <summary> /// Summary description for parent. /// </summary> public class parent : System.Web.UI.Page { protected System.Web.UI.WebControls.TextBox parentText1; protected System.Web.UI.WebControls.TextBox parentText2; protected System.Web.UI.WebControls.Button parentButton1; private void Page_Load(object sender, System.EventArgs e) { // Put user code to initialize the page here parentButton1.Attributes.Add("OnClick", "javascript:OpenChild()"); } #region Web Form Designer generated code override protected void OnInit(EventArgs e) { // // CODEGEN: This call is required by the ASP.NET Web Form Designer. // InitializeComponent(); base.OnInit(e); } /// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InitializeComponent() { this.Load += new System.EventHandler(this.Page_Load); } #endregion } }
child.aspx.csPHP Code:<%@ Page language="c#" Codebehind="child.aspx.cs" AutoEventWireup="false" Inherits="Popup.child" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>child</title>
<script language="javascript">
function GetData()
{
var text1 = child.childText1.value;
var text2 = child.childText2.value;
var args = new Array(text1, text2);
window.returnValue = args;
window.close();
}
function Init()
{
var text1 = "text1";
var text2 = "text2";
var args = new Array(text1, text2);
args = window.dialogArguments;
child.childText1.value = args[0].toString();
child.childText2.value = args[1].toString();
}
</script>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body onload="Init()" MS_POSITIONING="GridLayout">
<form id="child" method="post" runat="server">
<asp:TextBox id="childText1" style="Z-INDEX: 101; LEFT: 32px; POSITION: absolute; TOP: 32px"
runat="server" Font-Size="Smaller" Font-Names="Arial" Height="20px" Width="159px" MaxLength="10"></asp:TextBox>
<asp:TextBox id="childText2" style="Z-INDEX: 102; LEFT: 32px; POSITION: absolute; TOP: 64px"
runat="server" Font-Size="Smaller" Font-Names="Arial" Height="20px" Width="159px" MaxLength="10"></asp:TextBox>
<asp:Button id="childButton1" style="Z-INDEX: 100; LEFT: 72px; POSITION: absolute; TOP: 104px"
runat="server" Font-Size="Smaller" Font-Names="Arial" Width="72px" Text="Set Data"></asp:Button>
</form>
</body>
</HTML>
Code:using System; using System.Collections; using System.ComponentModel; using System.Data; using System.Drawing; using System.Web; using System.Web.SessionState; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.HtmlControls; namespace Popup { /// <summary> /// Summary description for child. /// </summary> public class child : System.Web.UI.Page { protected System.Web.UI.WebControls.TextBox childText1; protected System.Web.UI.WebControls.TextBox childText2; protected System.Web.UI.WebControls.Button childButton1; private void Page_Load(object sender, System.EventArgs e) { // Put user code to initialize the page here childButton1.Attributes.Add("OnClick", "javascript:GetData()"); } #region Web Form Designer generated code override protected void OnInit(EventArgs e) { // // CODEGEN: This call is required by the ASP.NET Web Form Designer. // InitializeComponent(); base.OnInit(e); } /// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InitializeComponent() { this.Load += new System.EventHandler(this.Page_Load); } #endregion } }


Reply With Quote