<%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false" Inherits="MySystem.ModalDialog.WebForm1" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm1</title>
<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">
<div align="center">
<form id="Form1" method="post" runat="server">
<asp:Label ID="label1" Runat="server" Font-Bold="True">从当前页面打开新窗口,并把变量传递到新窗口的例子,可以多次打开提交。</asp:Label><br>
<br>
<asp:TextBox ID="TextBox1" Runat="server" Width="600px">这是初始值,将传递到新窗口.</asp:TextBox><br>
<br>
<asp:Button ID="Button1" Runat="server" Text="打开窗口" Width="96px"></asp:Button>
</form>
</div>
</body>
</HTML>
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 MySystem.ModalDialog
{
/// <summary>
/// WebForm1 的摘要说明。
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.TextBox TextBox1;
protected System.Web.UI.WebControls.Label label1;
protected System.Web.UI.HtmlControls.HtmlForm Form1;
protected System.Web.UI.WebControls.Button Button1;
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
if(!this.IsClientScriptBlockRegistered("clientScript"))
{
string strScript = "<script>" + "\r\n";
strScript += "function OpenWin(){" + "\r\n";
strScript += " var str=window.showModalDialog('WebForm2.aspx',document.Form1.TextBox1.value)" + "\r\n";
strScript += " if(str!=null) document.Form1.TextBox1.value=str" + "\r\n";
strScript += "}" + "\r\n";
strScript += "</script>" + "\r\n";
this.RegisterClientScriptBlock("clientScript",strScript);
}
this.Button1.Attributes.Add("onclick", "OpenWin()");
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
}
}
<%@ Page language="c#" Codebehind="WebForm2.aspx.cs" AutoEventWireup="false" Inherits="MySystem.ModalDialog.WebForm2" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<TITLE>WebForm2</TITLE>
<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>
<frameset rows="0,*">
<frame src="about:blank">
<frame src="WebForm3.aspx">
</frameset>
</HTML>
<%@ Page language="c#" Codebehind="WebForm3.aspx.cs" AutoEventWireup="false" Inherits="MySystem.ModalDialog.WebForm3" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm3</title>
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
<meta content="C#" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
</HEAD>
<body id="MyBody" MS_POSITIONING="GridLayout" runat="server">
<form id="Form1" method="post" runat="server">
<asp:label id="label1" Runat="server">请输入您的大名:</asp:label><br>
<br>
<asp:textbox id="TextBox1" Runat="server" Width="558"></asp:textbox><br>
<br>
<asp:button id="button1" Runat="server" Text="提交"></asp:button></form>
</body>
</HTML>
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 MySystem.ModalDialog
{
/// <summary>
/// WebForm3 的摘要说明。
/// </summary>
public class WebForm3 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label label1;
protected System.Web.UI.WebControls.TextBox TextBox1;
protected System.Web.UI.WebControls.Button button1;
protected System.Web.UI.HtmlControls.HtmlControl MyBody;
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
if(this.IsPostBack)
{
string strScript = "<script>" + "\r\n";
strScript += " window.parent.returnValue='"+ this.TextBox1.Text.Replace("'","\\'") + "'\r\n";
strScript += " window.parent.close()" + "\r\n";
strScript += "</script>" + "\r\n";
if(!this.IsClientScriptBlockRegistered("clientScript"))
{
this.RegisterClientScriptBlock("clientScript",strScript);
}
}
if(!this.IsPostBack)
{
this.MyBody.Attributes.Add("onload","document.Form1.TextBox1.value=window.parent.dialogArguments");
}
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
}
}
http://dotnet.aspx.cc/ShowDetail.aspx?id=49ML4AO8-5PB3-4KNY-NJZD-LJOIOXV4M1X4
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm1</title>
<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">
<div align="center">
<form id="Form1" method="post" runat="server">
<asp:Label ID="label1" Runat="server" Font-Bold="True">从当前页面打开新窗口,并把变量传递到新窗口的例子,可以多次打开提交。</asp:Label><br>
<br>
<asp:TextBox ID="TextBox1" Runat="server" Width="600px">这是初始值,将传递到新窗口.</asp:TextBox><br>
<br>
<asp:Button ID="Button1" Runat="server" Text="打开窗口" Width="96px"></asp:Button>
</form>
</div>
</body>
</HTML>
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 MySystem.ModalDialog
{
/// <summary>
/// WebForm1 的摘要说明。
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.TextBox TextBox1;
protected System.Web.UI.WebControls.Label label1;
protected System.Web.UI.HtmlControls.HtmlForm Form1;
protected System.Web.UI.WebControls.Button Button1;
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
if(!this.IsClientScriptBlockRegistered("clientScript"))
{
string strScript = "<script>" + "\r\n";
strScript += "function OpenWin(){" + "\r\n";
strScript += " var str=window.showModalDialog('WebForm2.aspx',document.Form1.TextBox1.value)" + "\r\n";
strScript += " if(str!=null) document.Form1.TextBox1.value=str" + "\r\n";
strScript += "}" + "\r\n";
strScript += "</script>" + "\r\n";
this.RegisterClientScriptBlock("clientScript",strScript);
}
this.Button1.Attributes.Add("onclick", "OpenWin()");
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
}
}
<%@ Page language="c#" Codebehind="WebForm2.aspx.cs" AutoEventWireup="false" Inherits="MySystem.ModalDialog.WebForm2" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<TITLE>WebForm2</TITLE>
<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>
<frameset rows="0,*">
<frame src="about:blank">
<frame src="WebForm3.aspx">
</frameset>
</HTML>
<%@ Page language="c#" Codebehind="WebForm3.aspx.cs" AutoEventWireup="false" Inherits="MySystem.ModalDialog.WebForm3" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm3</title>
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
<meta content="C#" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
</HEAD>
<body id="MyBody" MS_POSITIONING="GridLayout" runat="server">
<form id="Form1" method="post" runat="server">
<asp:label id="label1" Runat="server">请输入您的大名:</asp:label><br>
<br>
<asp:textbox id="TextBox1" Runat="server" Width="558"></asp:textbox><br>
<br>
<asp:button id="button1" Runat="server" Text="提交"></asp:button></form>
</body>
</HTML>
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 MySystem.ModalDialog
{
/// <summary>
/// WebForm3 的摘要说明。
/// </summary>
public class WebForm3 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label label1;
protected System.Web.UI.WebControls.TextBox TextBox1;
protected System.Web.UI.WebControls.Button button1;
protected System.Web.UI.HtmlControls.HtmlControl MyBody;
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
if(this.IsPostBack)
{
string strScript = "<script>" + "\r\n";
strScript += " window.parent.returnValue='"+ this.TextBox1.Text.Replace("'","\\'") + "'\r\n";
strScript += " window.parent.close()" + "\r\n";
strScript += "</script>" + "\r\n";
if(!this.IsClientScriptBlockRegistered("clientScript"))
{
this.RegisterClientScriptBlock("clientScript",strScript);
}
}
if(!this.IsPostBack)
{
this.MyBody.Attributes.Add("onload","document.Form1.TextBox1.value=window.parent.dialogArguments");
}
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
}
}
http://dotnet.aspx.cc/ShowDetail.aspx?id=49ML4AO8-5PB3-4KNY-NJZD-LJOIOXV4M1X4
浙公网安备 33010602011771号