UpdatePanel 是否有任何解决方法?服务器传输问题?

发布于 2024-08-13 04:16:46 字数 366 浏览 11 评论 0原文

我正在尝试在 ASP.NET 应用程序中使用 UpdatePanel。不幸的是,我似乎无法做到这一点 如果我在应用程序中使用 Server.Transfer()

修改应用程序的该组件是不可能的 - 该体系结构广泛使用 Server.Transfer() - 本质上,每个页面请求都会通过此方法。此问题是否存在任何解决方法?如今,必须进行整页回发已经不流行了......

I'm trying to use an UpdatePanel in my ASP.NET application. Unfortunately, it seems that I can't do this if I am using Server.Transfer() in my application.

Modifying that component of the application is not possible - the architecture makes extensive use of Server.Transfer() - in essence, every page request goes through this method. Does any workaround exist for this issue exist? Having to do full-page postbacks is so unfashionable these days...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

贵在坚持 2024-08-20 04:16:46

我明白了!感谢Og的奇怪的外国语言博客 :)

要修复此问题,我可以简单地告诉 ASP.NET AJAX 客户端框架将部分请求直接定向到 Server.Transfer() 调用的真实目标。我非常害怕可能的副作用(谁知道这会跳过什么 - 基础设施确实有目的),但到目前为止它似乎运行良好。

这是修复问题的方法,在我的页面的 Load 事件中调用:

    ///
    /// 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);
        }
    }

I've got it! Thank Og for strange foreign language blogs :)

To fix it, I can simply tell the ASP.NET AJAX client-side framework to direct the partial request directly at the real target of the Server.Transfer() call. I am quite scared of the possible side-effects (who knows what this skips - the infrastructure does have a purpose) but it seems to be working fine so far.

Here is the method that fixes the problem, called in my page's Load event:

    ///
    /// 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);
        }
    }
明天过后 2024-08-20 04:16:46

这应该以更正确的方式工作:

如果您从控件的事件处理程序调用 Server.Transfer ,只需在更新面板的触发器部分中将该控件注册为 PostBackTrigger :

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

This should work in a more proper way:

if you call Server.Transfer from a control's event handler just register that control as a PostBackTrigger in the Triggers section of the update panel:

<Triggers>
    <asp:PostBackTrigger ControlID="controlId" />
</Triggers>
口干舌燥 2024-08-20 04:16:46

Response.Write("window.open('新标签页链接','_blank');");
Response.Write("this.window.location='链接到另一个页面';");

Response.Write("window.open('new tab page link','_blank');");
Response.Write("this.window.location='link to another page';");

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文