回答

4

我懂了!感谢Og的strange foreign language blogs :)

为了解决这个问题,我可以简单地告诉ASP.NET AJAX客户端框架直接在Server.Transfer()调用的实际目标上引导部分请求。我非常害怕可能产生的副作用(谁知道这会跳过 - 基础设施是否有目的),但目前似乎工作正常。

这里是能解决问题,叫我的网页加载事件的方法:

/// 
    /// Adds to the page a JavaScript that corrects the misbehavior of AJAX when a page is target of a Server.Transfer call. 
    /// 
    protected void AjaxUrlBugCorrection() 
    { 
     string actualFile = Server.MapPath(AppRelativeVirtualPath); 
     string redirectFile = Server.MapPath(Context.Request.FilePath); 
     string baseSiteVirtualPath = HttpRuntime.AppDomainAppVirtualPath; 

     if (actualFile != redirectFile) 
     { 
      System.Text.StringBuilder sbJS = new System.Text.StringBuilder(); 
      string actionUrl = string.Format("'{0}'", baseSiteVirtualPath + AppRelativeVirtualPath.Replace("~", String.Empty)); 
      sbJS.Append("Sys.Application.add_load(function(){"); 
      sbJS.Append(" var form = Sys.WebForms.PageRequestManager.getInstance()._form;"); 
      sbJS.Append(" form._initialAction = " + actionUrl + ";"); 
      sbJS.Append(" form.action = " + actionUrl + ";"); 
      sbJS.Append("});"); 
      ClientScript.RegisterStartupScript(this.GetType(), "CorrecaoAjax", sbJS.ToString(), true); 
     } 
    } 
+0

Sander是否可以发布aspx代码 –

+0

没有涉及aspx更改 - 只需在Page_Load中调用此方法,并且页面上的所有UpdatePanel将开始工作。 – Sander

0

这应该在一个更合适的工作方式:

如果你调用从一个控件的事件处理程序Server.Transfer刚寄存器在更新面板的触发器部,其控制作为PostBackTrigger:

<Triggers> 
    <asp:PostBackTrigger ControlID="controlId" /> 
</Triggers> 
0

回复于(“window.open(‘新标签页的链接’, '_空白');”); Response.Write(“this.window.location ='link to another page';”);

+0

欢迎来到SO。请提供一些背景给你的答案。只有链接和代码的答案不符合本网站的标准:http://stackoverflow.com/help/how-to-answer –

+0

我有我的列表页面上弹出小狗,所以当我用Server.Transfer去我的弹出页面。它没有正确重定向。因为弹出窗口显示的是加载和链接未在位置栏上更改。多数民众赞成在奇怪的,所以我用这个代码来解决这个问题,它的工作正常。 –

相关问题