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

ASP.NET
安装IE补丁后ASP.NET将无法运行
在ASP.Net中应用Javascript
用ASP.NET 1.1 新特征防止Script攻击
ASP.NET中在线用户统计的简单实现及讨论
ASP.NET中将数据输出到Excel
在ASP.NET中从SQL Server检索图片
ASP.NET系统用户权限设计与实现
利用ASP.NET技术动态生成HTML页面
大数量查询分页显示 微软的解决办法
ASP.NET WEB页面多语言支持解决方案
ASP.NET 2.0里轻松获取数据库连接统计数据
ASP.NET通过DSO访问分析服务器的权限问题
ASP实现禁止从外部提交数据
Asp.Net 使用 GDI+ 绘制3D饼图入门篇源码
在ASP.NET中点击一个按钮后让它变灰的简单方法
利用JS在asp.net中实现左导航页的隐藏
asp.net中一次更新DATAGRID中所有记录
用Asp.net屏蔽F5、Ctrl+N、Alt+F4
asp.net中用C#实现站点计数器用户控件
认识ASP.NET配置文件Web.config

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


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