• AjaxToolKit 页面间跳转引发Exception


    在项目中,一般页面与Page之间的跳转和传值,大家都会使用到以下几种跳转方式:

    如:Response.Redirect;Server.Transfer等

    那Server.Transfer一般是MS比较推荐我们在页面跳转时使用一种方式。

    那如果加上项目中使用ajax,那必然我们在页面跳转时,一般会遇到此类的问题(PageRequestManagerParseErrorException).

    如下图所示:

    ss

    那为什么会这样?

    Eilon Lipton's已经给我们很好的诠释

    What's a PageRequestManagerParserErrorException?

         The UpdatePanel control uses asynchronous postbacks to control which parts of the page get rendered. It does this using a whole bunch of JavaScript on the client and a whole bunch of C# on the server. Asynchronous postbacks are exactly the same as regular postbacks except for one important thing: the rendering. Asynchronous postbacks go through the same life cycles events as regular pages (this is a question I get asked often). Only at the render phase do things get different. We capture the rendering of only the UpdatePanels that we care about and send it down to the client using a special format. In addition, we send out some other pieces of information, such as the page title, hidden form values, the form action URL, and lists of scripts.

         As I mentioned, this is rendered out using a special format that the JavaScript on the client can understand. If you mess with the format by rendering things outside of the render phase of the page, the format will be messed up. Perhaps the most common way to do this is to call Response.Write() during Page's Load event, which is something that page developers often do for debugging purposes.

     

    解决方法:

    Code

    如上图所示,如果是BtnYes此按钮负责跳转页面的话,在UpdatePanel,Trigger中只要加上

    <asp:PostBackTrigger .../>即可(

    Add a PostBackTrigger to your UpdatePanel that points at the button. This works great if the button is declared statically through markup on the page.Call ScriptManager.RegisterPostBackControl() and pass in the button in question.

    后台代码:(不需要什么改动)

    protected void btnYes_Click(object sender, EventArgs e)  {

                Context.Items.Add("Key", "Value");
                Server.Transfer("TargetPage.aspx", true);

       。。。

    }

    OK! Over

    http://encosia.com/2007/06/19/the-easiest-way-to-break-aspnet-ajax-pages/

    http://www.nullify.net/ViewArticle.aspx?article=270
  • 相关阅读:
    rsync 配置
    DNS主从服务,子域授权,view视图,日志系统,压力测试
    ubuntu VNC server 黑屏 yum源更新(ubuntu16.04)
    HTTPD服务 openssl的https服务机制
    vmware Esxi 更换管理网卡IP
    httpd 虚拟主机建立之访问机制及其日志定义
    pxe kickstart 配置+TFTP+NFS多版本系统部署
    Linux nohup不输出日志文件的方法
    Tomcat部署时war和war exploded区别
    vim编辑超大文件
  • 原文地址:https://www.cnblogs.com/RuiLei/p/1152624.html
Copyright © 2020-2023  润新知