2012年3月26日月曜日

Response.Redirect doesnt work when the button is inside an ajax updatepanel

Hello,

I am getting the following error whenever I click a button inside an ajax updatepanel and it tries to Response.Redirect from the code behind.

Sys.WebForms.PageRequestManagerParserErrorException: The message received from the server could not be parsed. Common causes for this error are when the response is modified by calls to Response.Write(), response filters, HttpModules, or server trace is enabled.

Details: Error parsing near'

<!DOCTYPE html P'

I wasn't sure if it was my page not being correct or if it was something else. So I created two basic test pages test.aspx and test2.aspx. I click a button on text.aspx and it is supose to redirect to test2.aspx. This is a basic example giving the exact same error. So hopefully if I can get a resolution to this I could fix my real asp.net page. Thanks, Risso

Here is the test.aspx code:

<%

@dotnet.itags.org.PageLanguage="C#"AutoEventWireup="true"CodeFile="test.aspx.cs"Inherits="test" %>

<%

@dotnet.itags.org.RegisterAssembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"Namespace="System.Web.UI"TagPrefix="asp" %>

<!

DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<

htmlxmlns="http://www.w3.org/1999/xhtml">

<

headrunat="server"><linkhref="css/modaldialog.css"rel="stylesheet"type="text/css"/><title>Untitled Page</title>

</

head>

<

body><formid="form1"runat="server"><div><asp:ScriptManagerID="ScriptManager1"runat="server" ></asp:ScriptManager><asp:UpdatePanelID="UpdatePanel1"runat="server"><ContentTemplate><asp:ButtonID="Button1"runat="server"OnClick="Button1_Click2"Text="Button"/></ContentTemplate></asp:UpdatePanel></div></form>

</

body>

</

html>

HERE IS the Code behind code:

using

System;

using

System.Data;

using

System.Configuration;

using

System.Collections;

using

System.Web;

using

System.Web.Security;

using

System.Web.UI;

using

System.Web.UI.WebControls;

using

System.Web.UI.WebControls.WebParts;

using

System.Web.UI.HtmlControls;

public

partialclasstest : System.Web.UI.Page

{

protectedvoid Page_Load(object sender,EventArgs e)

{

}

protectedvoid Button1_Click2(object sender,EventArgs e)

{

Response.Redirect(

"~/test2.aspx");

}

}

HI.

Try to useServer.Transfer.


I did server.transfer shown below. It still gives the same error message. I put a breakpoint in the test2.aspx to see if it makes it to that pages_load event and it does, but the browser throws the exact same error message as listed in the first post. Any other ideas?

protectedvoid Button1_Click2(object sender,EventArgs e)

{

Server.Transfer("~/test2.aspx");

}


Hi, u must knwo that Response.Redirect and Server.Transfer work inside UpdatePanel.

can u share us the detail of the error that u have.


I tried your code and one of my own and it appears to be fine. Before you start beatin your head against the wall, try this...

This a must read from Eilon Lipton's Technical blog on Microsoft ASP.NET and ASP.NET AJAX when trying to solve PageRequestManagerParserErrorException errors!

http://weblogs.asp.net/leftslipper/archive/2007/02/26/sys-webforms-pagerequestmanagerparsererrorexception-what-it-is-and-how-to-avoid-it.aspx?CommentPosted=true#commentmessage A


Eilon Lipton's tips are great, I just add some more: Test "test2.aspx" for any invalid html markup, also test the response with fiddler.

Ok,

I found out were it is happening, but now I am not sure how to solve it since what I have to remove is also needed. I found that it was inside the web.config. I'm adding 2 httphandlers that were needed to fix other AJAX issues. I don't recall exactly what those issues were because this is a big application and it was a while back. I do remember these were needed to fix other ajax problems though. I do not want to remove these and have them break other ajax controls/tools. Anyone know a work around for this. I do know now that these httpHandlers are what is causing my Response.Redirect() issue in my updatepanel.

I removed the following lines from my web.config for it to work.

<

httpHandlers>

<

removeverb="*"path="*.asmx"/>

<

addverb="*"path="*.asmx"validate="false"type="Microsoft.Web.Services.ScriptHandlerFactory, Microsoft.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>

<

addverb="GET,HEAD"path="ScriptResource.axd"type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"validate="false"/>

</

httpHandlers>

Risso


Shoot, I just realized those were needed for the Ajax to work in IE. And by me removing those lines from the web.config it just does a normal postback and not an asynchronous call. That is why it worked for me. So really nothing has changed. I am back to nothing on why the response.redirect() doesn't work. You guys mentioned that you took the code and were able to get the response.redirect() to work. I'm not sure what in my environment could be any different. I'm running this off of localhost and I do not have IIS running.

Yeah. Have you tried a new website as ajax supported web? I tried both an iis and casini version of the test. What version of vs are you running?


Aesop:

Yeah. Have you tried a new website as ajax supported web? I tried both an iis and casini version of the test. What version of vs are you running?

Agree, use vs to create a new "ASP.NET Ajax-Enabled Web Site" or "ASP.NET Ajax CTP-Enabled Web Site", and use the web.config of the new site as a template, so carefully migrateyourweb.config into the template.

You can get a template web.config also from a similar path:

C:\Program Files\Microsoft ASP.NET\ASP.NET 2.0 AJAX Extensions\v1.0.61025

C:\Program Files\Microsoft ASP.NET\ASP.NET 2.0 AJAX Futures January CTP\v1.0.61025


Yes, I got it to work!! Thank you for your persistent responses. I did what you both recommended and started a new Ajax Application and pulled its web.config to compare to mine and went line by line with testing each line and found what I was missing. My web.config didn't have

<

httpModules>

<

addname="ScriptModule"type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>

</

httpModules>

Risso


Hi Rissoman,

Thanks your post. I have the problem like you. I took 2 days to find why I always take the PageRequestManagerParserErrorException. Well, I am upgrading the website, and missing the <httpModules>

Thanks again,

HUH


Thanks to everyone who posted about this. You've just saved me a lot of time and effort! Thanks!


HI,

Thanks a ton .for that code..

regards

Delia Joe

0 件のコメント:

コメントを投稿