阅读文章

AjaxToolKit-- 页面间跳转引发Exception

[日期:2008-04-15] 来源:  作者: [字体: ]

    
  在项目中,一般页面与Page之间的跳转和传值,大家都会使用到以下几种跳转方式:
  
  如:Response.Redirect;Server.Transfer等
  
  那Server.Transfer一般是MS比较推荐我们在页面跳转时使用一种方式。
  
  那如果加上项目中使用ajax,那必然我们在页面跳转时,一般会遇到此类的问题(PageRequestManagerParseErrorException).
  
  如下图所示:
  
  那为什么会这样?
  
  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.
  
   解决方法:
  
  如上图所示,如果是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
  
    


阅读:
录入:blue1000

评论 】 【 推荐 】 【 打印
上一篇:当程序员转行去做销售
下一篇:经验:使用.net 2.0中的TransactionScope碰到的问题
相关文章      
本文评论
发表评论


点评: 字数
姓名:

  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款