开发者

Response.Redirect in .NET 4.0

Response.Redirect() no longer working when upgrade the application to ASP.NET 4.0

it gives me the error:

Error: 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


you have to do this

string redirectURL=(a proper url goes here)

string script = "window.location='" + redirectURL + "';";

ScriptManager.RegisterStartupScript(this, typeof(Page), "RedirectTo", script, true);


UpdatePanel doesn't support resonse.redirect asynchronousely. You should either completely postback the page or avoid using it.

http://forums.asp.net/t/1539851.aspx/1?Response+Redirect+not+working+on+an+UpdatePanel+if+redirecting+to+a+ClickOnce+application+in+some+cases+

http://forums.asp.net/t/1392827.aspx

How to fix error: The message received from the server could not be parsed


Try passing True as the second argument like this:

Response.Redirect("http://...", true);


Had the same issue... You need to replace your version of the AjaxControlToolkit with the latest version built specifically for 4.0. It's a drop-in replacement, so it should affect anything else.See Ajaxcontroltoolkit on codeplex


We had the same issue. Resolved by using PostBackTrigger control

<Triggers>
   <asp:PostBackTrigger ControlID="UploadButton" />
</Triggers>

http://msdn.microsoft.com/en-us/library/system.web.ui.postbacktrigger.aspx


You should try doing it like this:

Response.Redirect("URL", false);
HttpContext.Current.ApplicationInstance.CompleteRequest();

You will be redirected and no error will be thrown.


I have been choking with this problem for entire days without advancing. Update contents of a panel, AsyncPostBackTrigger if the caller is outside updatePanel. If you want to redirect, you add it as PostBackTrigger. Both things on updatepanel using:

<asp:UpdatePanel ID="myUpdatePanel" runat="server" UpdateMode="Conditional">
    <ContentTemplate>
        <asp:LinkButton ID="link" runat="server" OnClick="link_Click"/>
    </ContentTemplate>
    <Triggers>
        <asp:PostBackTrigger ControlID="link" />
    </Triggers>
</asp:UpdatePanel>

My issue had to do with the controls being generated dinamically inside a custom control due a listview.

The solution:

ScriptManager.GetCurrent(this.Page).RegisterPostBackControl(myRedirectButton);

In my case, i was using a listview on the item data bound, so i got the control using:

Control myRedirectButton = ListViewDataItem.GetControl("controlId")

Keep in mind the diference between Async and not ones. It was the main point that i didnt notice it until very far.


You are trying to redirect to another page with an async request.

You can overload the Response.Redirect function and set it to false.

Response.Redirect("URL",false);

by setting it to false, it will terminate your current request and go to the next request.

I am 100% sure it will work for you.


This is also happening in one of our projects that we migrated from .Net 3.5 to .Net 4.0

The problem only occurs when compression is enabled. We had a custom Response Filter in the Global.asax.cs file to apply gzip compression to each response when supported by the browser.

The solution was to exclude the addition of that filter when requests were made by AJAX (an update panel). This is easy to distinguish because the request contains a X-MicrosoftAjax: Delta=true header. This can be accomplished by wrapping the logic inside an if:

if (Request.Headers["X-MicrosoftAjax"] != "Delta=true")
{
    // Compression logic here
}

See also: https://forums.asp.net/t/1564697.aspx

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜