zoukankan      html  css  js  c++  java
  • 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
  • 相关阅读:
    深入理解委托、匿名方法和 Lambda 表达式
    常见SQL问题
    LeetCode题解——四数之和
    把中台说清楚
    程序员们的三高:高并发、高性能、高可用
    论文查重是怎么查的
    LeetCode题解——最长回文子串
    六百字读懂 Git(转)
    SQL中ON和WHERE的区别
    链表排序之堆排序
  • 原文地址:https://www.cnblogs.com/RuiLei/p/1152624.html
Copyright © 2011-2022 走看看