asp.net(C#)弹出窗口返回值并刷新主窗体

本文介绍了一个使用ASP.NET Web窗体的应用示例,包括三个窗口:Windows1用于显示初始值并打开新窗口;Windows2展示如何使用iframe加载另一个页面;Windows3则作为iframe加载的内容。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

以下代码在环境:Microsoft Visual Studio 2005 (Service Pack1)下测试通过,目前也应用于项目中,感觉还行

此应用有三个窗口:

第一、Windows1.aspx

<%@PageLanguage="C#"AutoEventWireup="true"CodeBehind="Windows1.aspx.cs"Inherits="TaoNet.Client.Web.Windows1"%>

<!DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<htmlxmlns="http://www.w3.org/1999/xhtml">
<headid="Head1"runat="server">
<title>WebForm1</title>

</head>
<bodyms_positioning="GridLayout">
<divalign="center">
<formid="Form1"runat="server"method="post">
<asp:LabelID="Label1"runat="server"Font-Bold="true">
从当前页面打开新窗口,并把变量传递到新窗口的例子,可以多次打开提交。
</asp:Label><br>
<br>
<asp:TextBoxID="TextBox1"runat="server"Width="600px">这是初始值,将被传递到新窗口。</asp:TextBox><br>
<br>
<asp:ButtonID="Button1"runat="server"Text="打开窗口"Width="96px"/></form>
</div>
</body>
</html>
usingSystem;
usingSystem.Data;
usingSystem.Configuration;
usingSystem.Collections;
usingSystem.Web;
usingSystem.Web.Security;
usingSystem.Web.UI;
usingSystem.Web.UI.WebControls;
usingSystem.Web.UI.WebControls.WebParts;
usingSystem.Web.UI.HtmlControls;

namespaceTaoNet.Client.Web
...{
publicpartialclassWindows1:System.Web.UI.Page
...{
protectedvoidPage_Load(objectsender,EventArgse)
...{

intintWidth=500;
intintHeight=400;
stringvbCrLf=" ";
//在此处放置用户代码以初始化页面
if(!IsClientScriptBlockRegistered("clientScript"))
...{
stringstrScript="<script>"+vbCrLf;
strScript
+="functionOpenWin(){"+vbCrLf;
strScript
+="varstr=window.showModalDialog('Windows2.aspx',document.Form1.TextBox1.value,'dialogWidth="+intWidth+"px;dialogHeight="+intHeight+"px','scroll:yes')"+vbCrLf;
strScript
+="if(str!=null)document.Form1.TextBox1.value=str"+vbCrLf;
strScript
+="}"+vbCrLf;
strScript
+="</script>"+vbCrLf;
RegisterClientScriptBlock(
"clientScript",strScript);
}

Button1.Attributes.Add(
"onclick","OpenWin()");
//window.showModalDialog("modal.htm",obj,"dialogWidth=200px;dialogHeight=100px");

}

}

}
//------------------------------------------------------------------------------
//<auto-generated>
//此代码由工具生成。
//运行库版本:2.0.50727.42
//
//对此文件的更改可能会导致不正确的行为,并且如果
//重新生成代码,这些更改将会丢失。
//</auto-generated>
//------------------------------------------------------------------------------

namespaceTaoNet.Client.Web...{


/**////<summary>
///Windows1类。
///</summary>
///<remarks>
///自动生成的类。
///</remarks>

publicpartialclassWindows1...{

/**////<summary>
///Head1控件。
///</summary>
///<remarks>
///自动生成的字段。
///要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
///</remarks>

protectedglobal::System.Web.UI.HtmlControls.HtmlHeadHead1;

/**////<summary>
///Form1控件。
///</summary>
///<remarks>
///自动生成的字段。
///要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
///</remarks>

protectedglobal::System.Web.UI.HtmlControls.HtmlFormForm1;

/**////<summary>
///Label1控件。
///</summary>
///<remarks>
///自动生成的字段。
///要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
///</remarks>

protectedglobal::System.Web.UI.WebControls.LabelLabel1;

/**////<summary>
///TextBox1控件。
///</summary>
///<remarks>
///自动生成的字段。
///要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
///</remarks>

protectedglobal::System.Web.UI.WebControls.TextBoxTextBox1;

/**////<summary>
///Button1控件。
///</summary>
///<remarks>
///自动生成的字段。
///要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
///</remarks>

protectedglobal::System.Web.UI.WebControls.ButtonButton1;
}

}

第二、Windows2.aspx

<%@PageLanguage="C#"AutoEventWireup="true"CodeBehind="Windows2.aspx.cs"Inherits="TaoNet.Client.Web.Windows2"%>

<!DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<htmlxmlns="http://www.w3.org/1999/xhtml">
<headid="Head1"runat="server">
<title>WebForm2</title>

</head>
<framesetrows="0,*">
<framesrc="about:blank">
<framesrc="Windows3.aspx">
</frameset>
</html>
usingSystem;
usingSystem.Data;
usingSystem.Configuration;
usingSystem.Collections;
usingSystem.Web;
usingSystem.Web.Security;
usingSystem.Web.UI;
usingSystem.Web.UI.WebControls;
usingSystem.Web.UI.WebControls.WebParts;
usingSystem.Web.UI.HtmlControls;

namespaceTaoNet.Client.Web
...{
publicpartialclassWindows2:System.Web.UI.Page
...{
protectedvoidPage_Load(objectsender,EventArgse)
...{

}

}

}

//------------------------------------------------------------------------------
//<auto-generated>
//此代码由工具生成。
//运行库版本:2.0.50727.42
//
//对此文件的更改可能会导致不正确的行为,并且如果
//重新生成代码,这些更改将会丢失。
//</auto-generated>
//------------------------------------------------------------------------------

namespaceTaoNet.Client.Web...{


/**////<summary>
///Windows2类。
///</summary>
///<remarks>
///自动生成的类。
///</remarks>
publicpartialclassWindows2...{

/**////<summary>
///Head1控件。
///</summary>
///<remarks>
///自动生成的字段。
///要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
///</remarks>
protectedglobal::System.Web.UI.HtmlControls.HtmlHeadHead1;
}

}

第二、Windows3.aspx

<%@PageLanguage="C#"AutoEventWireup="true
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值