使用Server.Transfer方法跨页面传值实例

a.aspx:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="a.aspx.cs" Inherits="WebApplication1.a" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>无标题页</title> </head> <body> <form id="form1" runat="server"> <div> </div> <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label> <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" /> </form> </body> </html>

a.aspx.cs:

using System; using System.Collections; using System.Configuration; using System.Data; using System.Linq; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Xml.Linq; namespace WebApplication1 { public partial class a : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { Label1.Text = "A Page"; } public string Name { get { return Label1.Text; } } protected void Button1_Click(object sender, EventArgs e) { Server.Transfer("b.aspx"); } } }

 

b.aspx.cs:

using System; using System.Collections; using System.Configuration; using System.Data; using System.Linq; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Xml.Linq; namespace WebApplication1 { public partial class b : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { a apage = (a)Context.Handler; Response.Write(apage.Name); } } }

你可能感兴趣的:(server,object,XHTML,Class,asp,button)