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");
}
}
相關文章
asp.net開發(fā)微信派發(fā)現(xiàn)金紅包/H5網(wǎng)頁搶紅包功能(思路詳解)
這篇文章主要介紹了asp.net開發(fā)微信派發(fā)現(xiàn)金紅包/H5網(wǎng)頁搶紅包功能,本文給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下2021-03-03SQLServer 在Visual Studio的2種連接方法
這篇文章介紹了SQLServer 在Visual Studio的2種連接方法,有需要的朋友可以參考一下2013-09-09基于ABP架構開發(fā)的.Net Core項目部署到IIS問題匯總
這篇文章介紹了基于ABP架構開發(fā)的.Net Core項目部署到IIS問題匯總,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2022-06-06ASP.NET Core實現(xiàn)自定義WebApi模型驗證詳解
這篇文章主要給大家介紹了關于ASP.NET Core實現(xiàn)自定義WebApi模型驗證的相關資料,文中通過示例代碼介紹的非常詳細,對大家學習或者使用ASP.NET Core具有一定的參考學習價值,需要的朋友們下面來一起學習學習吧2019-08-08Repeater綁定dictionary數(shù)據(jù)源代碼及報錯解決
為大家講解下Repeater綁定dictionary數(shù)據(jù)源以及報錯處理的方法,感興趣的朋友可以參考下哈,希望對你有所幫助2013-04-04asp.net使用DataSet的ReadXml讀取XML文件及Stream流的方法
這篇文章主要介紹了asp.net使用DataSet的ReadXml讀取XML文件及Stream流的方法,實例分析了asp.net以字符流的形式讀取與寫入xml文件的相關技巧,需要的朋友可以參考下2016-06-06