欢迎您访问我爱IT技术网,今天小编为你分享的编程技术是:【2个页面间不通过Session与url的传值方式】,下面是详细的讲解!
2个页面间不通过Session与url的传值方式
下面是全部代码,已经编译通过。
Chuandi(传递)是名字空间
WebForm1:
<%@ Page language="c#" Codebehind="WebForm1.aspx.cs" Inherits="chuandi.WebForm1" %>
<HTML>
<HEAD>
<title>WebForm1</title>
</HEAD>
<body>
<form id="Form1" method="post" runat="server">
<asp:TextBox id="TextBox1" runat="server"></asp:TextBox>
<asp:Button id="Button1" runat="server" Text="传"></asp:Button>
</form>
</body>
</HTML>
using System;
namespace chuandi
{
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.TextBox TextBox1;
protected System.Web.UI.WebControls.Button Button1;
public string Text1
{
get
{
return this.TextBox1.Text;
}
}
private void Page_Load(object sender, System.EventArgs e)
{}
override protected void OnInit(EventArgs e)
{
InitializeComponent();
base.OnInit(e);
}
private void InitializeComponent()
{
this.Button1.Click +=new System.EventHandler(this.Button1_Click);
this.Load +=new System.EventHandler(this.Page_Load);
}
private void Button1_Click(object sender, System.EventArgs e)
{
Server.Transfer("WebForm2.aspx");
}
}
}
WebForm2:
<%@ Page language="c#" Codebehind="WebForm2.aspx.cs" Inherits="chuandi.WebForm2" %>
<%@ Reference Page="WebForm1.aspx" %>
<HTML>
<HEAD>
<title>WebForm2</title>
</HEAD>
<body>
<form id="Form1" method="post" runat="server">
<asp:Label id="Label1" runat="server">Label</asp:Label>
<asp:Button id="Button1" runat="server" Text="返回"></asp:Button>
</form>
</body>
</HTML>
using System;
namespace chuandi
{
public class WebForm2 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Button Button1;
protected System.Web.UI.WebControls.Label Label1;
public chuandi.WebForm1 wf1;
private void Page_Load(object sender, System.EventArgs e)
{
if(!IsPostBack)
{
wf1=(chuandi.WebForm1)Context.Handler;
Label1.Text="上页传来的是:"+wf1.Text1;
}
}
override protected void OnInit(EventArgs e)
{
InitializeComponent();
base.OnInit(e);
}
private void InitializeComponent()
{
this.Button1.Click +=new System.EventHandler(this.Button1_Click);
this.Load +=new System.EventHandler(this.Page_Load);
}
private void Button1_Click(object sender, System.EventArgs e)
{
Server.Transfer("WebForm1.aspx");
}
}
关于2个页面间不通过Session与url的传值方式的用户互动如下:
相关问题:MVC中的Session["str"]两个页面之间传值,为什么第...
答:因为第一次传值时,都要判断一下是否为空。如果Session["str"]为空时,就会报未将对象实例化的错误。 >>详细
相关问题:学习了ASP.NET各内部对象后,你认为实现在2个网页...
答:1 使用Querystring 方法 QueryString 也叫查询字符串, 这种方法将要传递的数据附加在网页地址(URL)后面进行传递。如页面A.aspx 跳转到页面B.aspx,可以用Request.Redirect("B.aspx?参数名称=参数值")方法,也可以用超链接:,页面跳转后,在目... >>详细
相关问题:PHP如何使用session在同一浏览器的两个页面传值
答:在第一个页面的开头加上以下代码: 在同一工程的其他文件中加入以下就能访问上面设置的session变量的值 >>详细
- 【asp】asp.net url重写浅谈-net-url重写
- 【DataSet】DataSet、DataTable、DataRow区别详解
- 【asp】asp.net 动态添加多个用户控件-net-动态添
- 【创建】ASP.NET Web API教程 创建域模型的方法详
- 【Asp】Asp.net 页面调用javascript变量的值-net-
- 【ASP】ASP.NET 5升级后如何删除旧版本的DNX-NET5
- 【404页面】ASP.NET设置404页面返回302HTTP状态码
- 【Visual】分享Visual Studio原生开发的10个调试
- 【全局】.net全局定时定期执行某些操作在Global.a
- 【asp】asp.net ubb使用代码-net-ubb使用
- 评论列表(网友评论仅供网友表达个人看法,并不表明本站同意其观点或证实其描述)
-
