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

ASP.NET
ASP.NET下MVC设计模式的实现
ASP.NET中利用cookies保持客户端信息
有关TextBox中输入字符控制的一种解决办法
ASP.NET访问Oracle数据库的方法
追踪ASP.NET代码里的bug
在asp.net中为Web用户控件添加属性和事件
使用.NET实现断点续传
ASP.NET Whidbey中实现Provider
使用函数传递参数来执行数据库操作
ASP.NET中实现模版的动态加载
用Repeater控件显示数据
五种常见的ASP.NET安全缺陷
利用Treeview实现树形列表
将Asp.net页面输出为HTML
不走寻常路 设计ASP.NET应用程序的七大绝招
ASP.NET中的HTTP模块和处理程序
充分利用ASP.NET的三种缓存提高站点性能
在ASP.NET中使用Treeview控件和XML
ASP.NET+XML Web服务客户端创建Web服务
ASP.NET中不定级动态菜单的实现

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


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-08-14   浏览: 56 ::
收藏到网摘: 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");
}
}