The following code is tested in VS2008 by
<%@ Page language="C #"autoeventwireup="true"codefile="WebForm1.aspx.cs"inherits="WebForm1"%><! DOCTYPE HTML Public"-//W3C//DTD XHTML 1.0 transitional//en" "HTTP://WWW.W3.ORG/TR/XHTML1/DTD/XHTML1-TRANSITIONAL.DTD">"http://www.w3.org/1999/xhtml">"Server"> <title></title>"Form1"runat="Server"> <div> <asp:textbox id="TextBox1"runat="Server"></asp:textbox><br/> <asp:button id="Button1"runat="Server"text="Button"onclick="Button1_Click"/> </div> </form></body>View CodeusingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingsystem.web;usingSystem.Web.UI;usingSystem.Web.UI.WebControls; Public Partial classwebform1:system.web.ui.page{ Public stringTime {Get{returnDateTime.Now.ToString ();} } Public stringTestfun () {return "Function of WebForm1 called"; } protected voidPage_Load (Objectsender, EventArgs e) {CONTEXT.ITEMS.ADD ("Context","Context from Form1"); } protected voidButton1_Click (Objectsender, EventArgs e) { //This . TextBox2.Text =request ["TextBox1"]. ToString ();Server.Transfer ("webform2.aspx",true);//when the second parameter is false, the contents of TextBox1 cannot be obtained in webform2.aspx }}
View CodeWebform2.aspx Source
<%@ Page language="C #"autoeventwireup="true"codefile="WebForm2.aspx.cs"inherits="WebForm2"%><%@ Reference page="~/webform1.aspx"%><%--Notice here--%><! DOCTYPE HTML Public"-//W3C//DTD XHTML 1.0 transitional//en" "HTTP://WWW.W3.ORG/TR/XHTML1/DTD/XHTML1-TRANSITIONAL.DTD">"http://www.w3.org/1999/xhtml">"Server"> <title></title>"Form1"runat="Server"> <div> <asp:literal id="Literal1"runat="Server"></asp:Literal> </div> </form></body>View CodeusingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingsystem.web;usingSystem.Web.UI;usingSystem.Web.UI.WebControls; Public Partial classwebform2:system.web.ui.page{protected voidPage_Load (Objectsender, EventArgs e) { stringStrtxt =""; WebForm1 Oform= (WEBFORM1) This. Context.Handler; Strtxt+="Value of Textbox:"+ request.form["TextBox1"] +"<br>"; Strtxt+="Time Property :"+ Oform.time +"<br>"; Strtxt+="Context String:"+ context.items["Context"]. ToString () +"<br>"; Strtxt+ = Oform.testfun () +"<br>"; Literal1.text=Strtxt; }}
View CodeExcerpted from: http://blog.csdn.net/vchao13/article/details/5004502