当前位置:雨林木风下载站 > 网页设计教程 > 详细页面

2个aspx页面间传递引用对象。

2个aspx页面间传递引用对象。

更新时间:2025-12-27 文章作者:未知 信息来源:网络 阅读次数:

有不少文章讨论怎么在两个页面间传递引用,如果你页面上的对象设置为public的话,你就可以传递他们在页面间。在页面间传递是使用Server.Transfer替代Response.Redirect就可...
有不少文章讨论怎么在两个页面间传递引用,如果你页面上的对象设置为public的话,你就可以传递他们在页面间。在页面间传递是使用
Server.Transfer替代Response.Redirect就可以。
例子:

-------------In Page A codebehind:

public class PageA : System.Web.UI.Page
{
public System.Web.UI.WebControls.TextBox TextBox1;
public System.Web.UI.WebControls.Button Button1;

// standard page code (Page_Load, etc)
// ....
// ....

private void Button1_Click(object sender, System.EventArgs e)
{
Server.Transfer("b.aspx");
}
}


-------------In Page B codebehind:


private void Page_Load(object sender, System.EventArgs e)
{
PageA myAPage = Context.Handler as PageA;
string textboxFromPageA = myAPage.TextBox1.Text;
}

因为当使用Server.Transfer时所有的对象(A and B)在服务器上当时都是活动的,你可以引用任何东西。

稍微修改一下b.aspx(uestc95 提供):

Page myPage =(Page) Context.Handler;
string textboxFromPageA;
textboxFromPageA = ((TextBox)myPage.FindControl("TextBox1")).Text;


这样在A.aspx中就可以正常的使用protected类型的了。

Good Luck!

温馨提示:喜欢本站的话,请收藏一下本站!

本类教程下载

系统下载排行