日期:2014-05-17  浏览次数:20415 次

ASP.NET,执行Server.Transfer(System.Web.UI.Page)出现页面事件不响应
我建立了一个FirstPage.aspx,里面有一个按钮button,其事件为:
C# code
Response.Redirect("~/SecondPage.aspx");

现在外部代码生成Page类的FirstPage(其中省略了一些代码):
C# code

public class MyHandler : IHttpHandler
{
 public void ProcessRequest(HttpContext context)
 {
  if (context != null && context.Server != null)
  {
  page1 =   BuildManager.CreateInstanceFromVirtualPath("~/FirstPage.aspx", typeof(Page)) as Page;
  context.Server.Transfer(page1, false);
  }
}


结果发现这种方式生成的FirstPage,按里面的button不能跳转到SecondPage.aspx,只能刷新页面而已。

目前该如何解决这个跳转不成功的问题呢?

------解决方案--------------------
为什么设置 preserveForm 参数为false呢?

设置为true,我也不确定可以触发事件(因为这毕竟跟正常处理页面生命周期是两个不同的程序)。但是设置为false,显然是没有理由触发任何事件的。

实际上既然你使用
C# code
context.Redirect("~/first.aspx?action=button");