两个aspx页面间传递引用对象
2008-02-12 11:58
295 查看
有不少文章讨论怎么在两个页面间传递引用,如果你页面上的对象设置为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
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
相关文章推荐
- 两个aspx页面间传递引用对象
- 两个aspx页面间传递引用对象。
- 两个JSP页面之间如何传递一个对象?比如一个LIST或者HASHMAP?以及为什么有时候REQUEST.GETATTRIBUTE("NAME")取不到值?
- android中通过实现Parcelable来在两个页面之间传递对象的简单使用
- 使用Server.Transfer在两个ASPX页面间传递参数
- 使用Server.Transfer在两个ASPX页面间传递参数
- vs2010 视图 aspx页面创建控件时出错 未将对象引用设置到对象的实例
- 使用Server.Transfer在两个ASPX页面间传递参数
- .net vs2010 视图aspx页面创建控件时出错 未将对象引用设置到对象的实例
- 两个html页面之间传递值的方法
- 在两个ASP.NET页面之间传递值
- 在SharePoint Server 2010 的管理中心,点击“配置管理帐户”,就会在ManagedAccounts.aspx页面出现,“对象不存在”的出错信息应对方法!!!!
- 在两个ASP.NET页面之间传递值(3种方法)
- 一切传递都是对象的引用
- [转][Silverlight] aspx页面上传递参数给Silverlight插件的方法
- ASP.NET两个页面之间传递值的几种方式
- 菜鸟必须了解的两个常识 - 值传递or引用传递
- JSON:在两个activity之间使用intent传递list类型的对象
- 【java】值传递和引用传递---对象作为方法的参数传入属于哪种传递
- 使用Intent对象来实现两个(或多个)Activity之间的跳转,并实现在Activity之间传递参数。