[导入]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

BrianLei 2008-04-14 13:14 发表评论

文章来源:http://www.cnblogs.com/RuiLei/archive/2008/04/14/1152624.html
posted @ 2008-04-15 10:03  潜水员  阅读(159)  评论(0编辑  收藏  举报