2012年3月26日月曜日

Response.Redirect doesnt work with UpdatePanel in Beta 1

I have a page with an update panel that contains a few buttons that need to be able to redirect to another page. The script manager is located on a master page.

Every time one of those buttons are clicked, i get one of two errors:

    If the button is inside of a gridview, i get this error:
    Sys.WebForms.PageRequestManagerParserErrorException: The message received from the server could not be parsed.
    If the button is NOT inside of a gridview, i get this error:
    Sys.WebForms.PageRequestManagerParserErrorException: An unknown error occurred while processing the request on the server. The status code returned from the server was: 302

Here's a test aspx page that I set up:

1<%@dotnet.itags.org. Page Language="VB" title="Untitled Page" MasterPageFile="~/main.master" AutoEventWireup="false" CodeFile="test.aspx.vb" Inherits="test" %>2<%@dotnet.itags.org. Register Assembly="Microsoft.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" Namespace="Microsoft.Web.UI" TagPrefix="ajax" %>3<asp:Content ID="Content1" ContentPlaceHolderID="plhContent" Runat="Server">4 <ajax:UpdatePanel runat="server">5 <ContentTemplate>6 <asp:Label runat="server" ID="lblTime" /><br />7 <asp:Button runat="server" ID="btnRefresh" Text="Refresh" /><br />8 <asp:Button runat="server" ID="btnRedirect" Text="Redirect" /><br />9 <asp:LinkButton runat="server" ID="lnkRedirect" Text="ASP Linkbutton" /><br />10 <a href="http://www.google.com/" title="test redirect">HTML Hyperlink</a>11 </ContentTemplate>12 </ajax:UpdatePanel>13</asp:Content>
And here's the codebehind:
1PartialClass test2Inherits System.Web.UI.Page34Protected Sub Page_Load(ByVal senderAs Object,ByVal eAs System.EventArgs)Handles Me.Load5 lbltime.Text = now()6End Sub78 Protected Sub btnRedirect_Click(ByVal senderAs Object,ByVal eAs System.EventArgs)Handles btnRedirect.Click9 Response.Redirect("http://www.google.com/",True)10End Sub1112 Protected Sub btnRefresh_Click(ByVal senderAs Object,ByVal eAs System.EventArgs)Handles btnRefresh.Click13 lblTime.Text = Now()14End Sub1516 Protected Sub lnkRedirect_Click(ByVal senderAs Object,ByVal eAs System.EventArgs)Handles lnkRedirect.Click17 Response.Redirect("http://www.google.com/",True)18End Sub19End Class


The LinkButton causes the same error, so it's not just limited to the button control. It looks like it affect anything that posts back to the server and causes a redirect.

Thanks for any help you can give me!

We found this out today too. The fix is to pass a location.href back to user.

ScriptManager.RegisterStartupScript(pnlYourUpdatePanel,this.GetType(),"redirectMe","location.href='blah.aspx';",true);

Sorry it is in C#... Hope this helps.


hello.

i've just built a sample project with the following code:

master page:

<%@. Master Language="VB" %
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
<script runat="server"
</script
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:scriptmanager runat="server" ID="manager" />
<asp:contentplaceholder id="ContentPlaceHolder1" runat="server">
</asp:contentplaceholder>
</div>
</form>
</body>
</html>

page:

<%@. Page Language="VB" MasterPageFile="~/MasterPage.master" Title="Untitled Page" %>
<script runat="Server">
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
lblTime.Text = Now()
End Sub

Protected Sub btnRedirect_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnRedirect.Click
Response.Redirect("http://www.google.com/", True)
End Sub

Protected Sub btnRefresh_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnRefresh.Click
lblTime.Text = Now()
End Sub

Protected Sub lnkRedirect_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkRedirect.Click
Response.Redirect("http://www.google.com/", True)
End Sub
</script>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<asp:updatePanel runat="server" id="panel">
<contenttemplate>
<asp:Label runat="server" ID="lblTime" /><br />
<asp:Button runat="server" ID="btnRefresh" Text="Refresh" /><br />
<asp:Button runat="server" ID="btnRedirect" Text="Redirect" /><br />
<asp:LinkButton runat="server" ID="lnkRedirect" Text="ASP Linkbutton" /><br />
<a href="http://links.10026.com/?link=http://www.google.com/" title="test redirect">HTML Hyperlink</a>
</contenttemplate>
</asp:updatePanel>
</asp:Content
everything is working here with the beta extensions. are you sure you've set up web.config correctly?


Luis,

When looking at the XMLHttpResponse google.com is being returned which is causing the parser error. Not sure how you are getting this to work with the Beta release?? Also, not sure how config would cause this?

Matt


hello.

well just recalled one problem i've seen before where the users updated the prefix but left it pointing to the old ctp dll which was still in the bin folder and it just blow everything apart. btw, here's what i'm getting back from the server side in response to a click over the redirect button (2nd one from the top):


22|pageRedirect||http://www.google.com/|


Luis Abreu:

everything is working here with the beta extensions. are you sure you've set up web.config correctly?

I think I do. I have a Microsoft.Web.Extensions assembly in the web.config. Is there aything else I need?

1<compilation debug="true" strict="false" explicit="true">2 <assemblies>3 <add assembly="System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>4 <add assembly="System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>5 <add assembly="Microsoft.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>6 </assemblies>7</compilation>


Luis Abreu:

well just recalled one problem i've seen before where the users updated the prefix but left it pointing to the old ctp dll which was still in the bin folder and it just blow everything apart.

I did delete the old CTP DLL, and added the new assembly registration to the top of the page:

1<%@. Register Assembly="Microsoft.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" Namespace="Microsoft.Web.UI" TagPrefix="ajax" %>2

hello again.

can you confirm the response you're getting back from the server? is it similar to the one i've shown before?


How do I access the server response information?

hello.

use fiddler. if you're using ie, you must create a site in IIS and then use the name of the machine (http://machinename/site). if you're using firefox, configure it so that it uses a local proxy (127.0.0.1 port 8888 if i'm not mistaken).


It is definitely in the config. Again... good call Luis... you are missing these values in your config and this should cure the problem.

<httpModules><add name="WebResourceCompression" type="Microsoft.Web.Handlers.WebResourceCompressionModule, Microsoft.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/><add name="ScriptModule" type="Microsoft.Web.UI.ScriptModule, Microsoft.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/></httpModules>
Thank Luis for that one. =)
P.S. That is under httpHandlers

That worked! You guys are awesome.


Thanks!


Thanks - Guys!

I was experiencing the same problem in Beta 2, which this solution apparently resolved that issue.


Hi Guys!

I Got the Same error in my current project. I cant redirect to another page from inside the UpdatePanel. Finally I saw this forum and got a wonder result and answer. Its really amazing and thanks a lot for u all guys..

rgds,

Senthil

0 件のコメント:

コメントを投稿