看了一篇文章关于Server.Transfer传值。 有问题请教

che2piaopiao che2piaopiao 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
1.在receive.aspx: 根本调不出 send来。
send.aspx: 

public string Name
{
get { return "honge"; }
}

protected void Button1_Click(object sender, EventArgs e)
{ Server.Transfer("receive.aspx"); }


receive.aspx:

send d = Context.Handler as send ;
if (d != null) { Response.Write(d.Name);这样可以得到参数值。 }



2.WebForm1 也调不出

在第二个页面中,我们就可以使用Context.Handler属性来获得前一个页面实例对象的引用,通过它,就可以使用存取前一个页面的控件的值了

  以下代码综合实现上述步骤过程的代码:

  源页面代码:

  把以下的代码添加到页面中

  

public string Name  {   get   {   return TextBox1.Text;   }  }  public string EMail  {   get   {   return TextBox2.Text;   }  }


  然后调用Server.Transfer方法

  

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


  目标页面代码:

  

private void Page_Load  (object sender, System.EventArgs e)  {   file://create instance of source web form   WebForm1 wf1;   file://get reference to current handler instance   wf1=(WebForm1)Context.Handler;   Label1.Text=wf1.Name;   Label2.Text=wf1.EMail;  }



...全文
评论 4
收藏 已收藏
分享
返回顶部
che2piaopiao
.NET社区 62,274 成员 668,968 内容