2個(gè)頁(yè)面間不通過(guò)Session與url的傳值方式
下面是全部代碼,已經(jīng)編譯通過(guò)。
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="上頁(yè)傳來(lái)的是:"+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");
}
}
相關(guān)文章
ASP.NET 站點(diǎn)地圖(sitemap)簡(jiǎn)明教程
畢業(yè)設(shè)計(jì)折騰了近一個(gè)月的時(shí)間,也將近完工階段。下個(gè)禮拜六是論文答辯時(shí)間,所以今天晚上就抽空想去弄一下站點(diǎn)地圖。不怕大俠們笑話,我在以前還真沒(méi)弄過(guò)這些。以前開(kāi)發(fā)過(guò)幾個(gè)項(xiàng)目都是系統(tǒng)類,也就沒(méi)怎么涉及了2012-04-04
ASP.NET Session的七點(diǎn)認(rèn)識(shí)小結(jié)
ASP.NET Session的使用當(dāng)中我們會(huì)遇到很多的問(wèn)題,那么這里我們來(lái)談下經(jīng)常出現(xiàn)的一些常用ASP.NET Session的理解2011-07-07
asp.net(vb.net)獲取真實(shí)IP的函數(shù)
asp.net(vb.net)獲取真實(shí)IP的函數(shù),需要的朋友可以參考下。2010-11-11
數(shù)據(jù)綁定之DataFormatString使用介紹
DataFormatString是很多Asp.Net控件都有的屬性,如GridView等等,下面簡(jiǎn)單介紹一下這個(gè)屬性,感興趣的朋友不要錯(cuò)過(guò)2013-10-10
.NET實(shí)現(xiàn)文件跨服務(wù)器上傳下載的方法
這篇文章主要給大家介紹了.NET文件如何實(shí)現(xiàn)跨服務(wù)器上傳下載的方法,文中通過(guò)圖片介紹的很詳細(xì),相信對(duì)大家的理解和學(xué)習(xí)具有一定的參考借鑒價(jià)值,有需要的朋友們可以跟著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧。2016-12-12

