下面是全部代码,已经编译通过。
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”);
}
}