两个aspx页面间传递引用对象

有不少文章讨论怎么在两个页面间传递引用,如果你页面上的对象设置为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类型的了。

 

转自:http://www.zzchn.com/edu/20070914/38507.shtml

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值