Back to Devexpress

Response.Redirect cannot be called in a Page callback

aspnet-403752-troubleshooting-server-side-issues-response-redirect-cannot-be-called-in-page-callback.md

latest1.6 KB
Original Source

Response.Redirect cannot be called in a Page callback

  • May 30, 2024

Error Description

This error can occur when you use the HttpResponse.Redirect method to navigate to another page on a callback. A callback request expects a response from the same page and a redirect to another page causes the “Response.Redirect cannot be called in a Page callback” error.

Solution

Use the RedirectOnCallback(String) method to redirect a page to the specified URL when server-side processing is complete:

For v14.2 and earlier (BC2626):

csharp
string TARGET_URL = ...;  
if(Page.IsCallback)  
    DevExpress.Web.ASPxWebControl.RedirectOnCallback(TARGET_URL);  
else  
    Response.Redirect(TARGET_URL);
vb
Dim TARGET_URL As String = ...  
If Page.IsCallback Then  
    DevExpress.Web.ASPxWebControl.RedirectOnCallback(TARGET_URL)  
Else  
    Response.Redirect(TARGET_URL)  
End If

For v14.1 and older:

csharp
string TARGET_URL = ...;  
if(Page.IsCallback)  
    DevExpress.Web.ASPxWebControl.RedirectOnCallback(TARGET_URL);  
else  
    Response.Redirect(TARGET_URL);
vb
Dim TARGET_URL As String = ...  
If Page.IsCallback Then  
    DevExpress.Web.ASPxWebControl.RedirectOnCallback(TARGET_URL)  
Else  
    Response.Redirect(TARGET_URL)  
End If