2个页面间不通过Session与url的传值方式。

下面是全部代码,已经编译通过。
Chuandi(传递)是名字空间

WebForm1:

1@ Page language="c#" Codebehind="WebForm1.aspx.cs" _ Inherits="chuandi.WebForm1  " _ 
 1<html>
 2<head>
 3<title>WebForm1</title>
 4</head>
 5<body>
 6<form id="Form1" method="post" runat="server">
 7<asp:textbox id="TextBox1" runat="server"></asp:textbox>
 8<asp:button id="Button1" runat="server" text="传"></asp:button>
 9</form>
10</body>
11</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:

1@ Page language="c#" Codebehind="WebForm2.aspx.cs" _ Inherits="chuandi.WebForm2"  _ 

_ ``` @ Reference Page="WebForm1.aspx"

1_
WebForm2
Label
``` 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"); } }
Published At
Categories with Web编程
Tagged with
comments powered by Disqus