当前位置: 首页 > 图文教程 > 网络编程 > ASP.NET > 2个页面间不通过Session与url的传值方式

ASP.NET
Asp.Net使用POST方法最简单的实现
实现.NET应用程序的自动更新
优秀ASP.NET程序员修炼之路
ASP.NET中实现模板页
在ASP.Net 2.0中实现多语言界面的方法
小议优化ASP.NET应用性能之Cache篇
.net开发投票机的思路
浅析CMS内容管理系统的两种方案
ASP.NET 2.0中动态修改页面标题
“您无权查看该网页”的原因和解决方法
将一个图片按比例缩放显示在一个Frame中
编程使用资源文件实现多语言页面(In Action)
.Net编程的多个小技巧
asp.net2.0学习历程-菜鸟到中级程序员的飞跃
asp.net如何连接sql server2000数据库
FCKeditor 2.6在ASP.NET中的配置方法
使用ASP.NET开发移动通讯的几种方法
ASP.NET 2.0的URL映射的实现方法
如何在Asp.net中使用HtmlArea编辑器
ASP.NET 2.0 中实现跨页提交

ASP.NET 中的 2个页面间不通过Session与url的传值方式


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-08-14   浏览: 61 ::
收藏到网摘: n/a

下面是全部代码,已经编译通过。
Chuandi(传递)是名字空间

WebForm1:
<%@Pagelanguage="c#"Codebehind="WebForm1.aspx.cs"Inherits="chuandi.WebForm1"%>
<HTML>
<HEAD>
<title>WebForm1</title>
</HEAD>
<body>
<formid="Form1"method="post"runat="server">
<asp:TextBoxid="TextBox1"runat="server"></asp:TextBox>
<asp:Buttonid="Button1"runat="server"Text="传"></asp:Button>
</form>
</body>
</HTML>
usingSystem;
namespacechuandi
{
publicclassWebForm1:System.Web.UI.Page
{
protectedSystem.Web.UI.WebControls.TextBoxTextBox1;
protectedSystem.Web.UI.WebControls.ButtonButton1;
publicstringText1
{
get
{
returnthis.TextBox1.Text;
}
}
privatevoidPage_Load(objectsender,System.EventArgse)
{}
overrideprotectedvoidOnInit(EventArgse)
{
InitializeComponent();
base.OnInit(e);
}
privatevoidInitializeComponent()
{
this.Button1.Click+=newSystem.EventHandler(this.Button1_Click);
this.Load+=newSystem.EventHandler(this.Page_Load);
}
privatevoidButton1_Click(objectsender,System.EventArgse)
{
Server.Transfer("WebForm2.aspx");
}
}
}


WebForm2:
<%@Pagelanguage="c#"Codebehind="WebForm2.aspx.cs"Inherits="chuandi.WebForm2"%>
<%@ReferencePage="WebForm1.aspx"%>
<HTML>
<HEAD>
<title>WebForm2</title>
</HEAD>
<body>
<formid="Form1"method="post"runat="server">
<asp:Labelid="Label1"runat="server">Label</asp:Label>
<asp:Buttonid="Button1"runat="server"Text="返回"></asp:Button>
</form>
</body>
</HTML>
usingSystem;
namespacechuandi
{
publicclassWebForm2:System.Web.UI.Page
{
protectedSystem.Web.UI.WebControls.ButtonButton1;
protectedSystem.Web.UI.WebControls.LabelLabel1;
publicchuandi.WebForm1wf1;
privatevoidPage_Load(objectsender,System.EventArgse)
{
if(!IsPostBack)
{
wf1=(chuandi.WebForm1)Context.Handler;
Label1.Text="上页传来的是:"+wf1.Text1;
}
}
overrideprotectedvoidOnInit(EventArgse)
{
InitializeComponent();
base.OnInit(e);
}
privatevoidInitializeComponent()
{
this.Button1.Click+=newSystem.EventHandler(this.Button1_Click);
this.Load+=newSystem.EventHandler(this.Page_Load);
}
privatevoidButton1_Click(objectsender,System.EventArgse)
{
Server.Transfer("WebForm1.aspx");
}
}