<asp:TextBox runat="server" ID="PbValue" Text="Geforce TX280"></asp:TextBox>
<asp:Button runat="server" ID="btn6" Text="跨页面传送方式" PostBackUrl="~/GetValues.aspx" />
以上代码中,TextBox控件的“Text”属性为“Geforce TX280”,这是所需要传送的值。而Button控件的“PostBackUrl”属性指定了GetValues.aspx页面,该页面即可接收所需传递的值。在GetValues.aspx.cs的Page_Load方法中,编写以下代码。
//PreviousPage为向当前页面传输控件的页面
if (PreviousPage != null)
{
//从PreviousPage容器中搜索“ID”为PbValue的控件,并转换为TextBox类型
TextBox tb = (TextBox)PreviousPage.FindControl("PbValue");
//如果tb不是空引用
if (tb != null)
{
//将tb的“Text”属性值给str变量
string str = tb.Text;
}
}
以上代码轻松获得了前一个页面中TextBox控件的“Text”属性值,这种方法比调用HttpServerUtility对象的Transfer方法更加快捷,并减少了处理步骤。
以上为常用的页面间传值方法,如果有特殊需要,还可以使用其他方法,例如通过数据库存储临时数据等。








