ASP.NET向父页面提交内容并关闭子页面
pageMain.aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="pageMain.aspx.cs" Inherits="NetSamples.aspnet.pageMain" %>
<!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 ID="Button1" runat="server" Text="弹出页面" />
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</div>
</form>
</body>
</html>
pageMain.aspx.cs:
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
namespace NetSamples.aspnet
{
public partial class pageMain : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string openNew = "javascript:window.open('pagePop.aspx','查找','height=250,width=550,top='+(screen.availHeight-250)/2+',left='+(screen.availWidth-550)/2+',toolbar=no,menubar=no,scrollbars=yes,resizable=yes,location=no,status=yes');return false;";
Button1.Attributes.Add("onclick", openNew);
}
}
}
pagePop.aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="pagePop.aspx.cs" Inherits="NetSamples.aspnet.pagePop" %>
<!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:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="提交" onclick="Button1_Click" />
</div>
</form>
</body>
</html>
pagePop.aspx.cs:
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
namespace NetSamples.aspnet
{
public partial class pagePop : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{ 
}
protected void Button1_Click(object sender, EventArgs e)
{
// 向父页面提交内容
//this.Response.Write("<script language='javascript'>window.opener.parent.frames['form1'].document.all.TextBox1.value='" + TextBox1.Text + "';</script>");
//this.Response.Write("<script language='javascript'>window.opener.parent.frames['form1'].document.form1.submit();window.close();</script>");
Type cstype = this.GetType();
ClientScript.RegisterStartupScript(cstype, "", "<script language='javascript'>window.opener.parent.frames['form1'].document.all.TextBox1.value='" + TextBox1.Text + "';window.opener.parent.frames['form1'].document.form1.submit();window.close();</script>");
}
}
}
本贴子以“现状”提供且没有任何担保,同时也没有授予任何权利
This posting is provided "AS IS" with no warranties, and confers no rights.
This posting is provided "AS IS" with no warranties, and confers no rights.


浙公网安备 33010602011771号