Robert
Robert

Reputation: 51

Response Redirect cannot be called in Page callback?

I am getting the following error when I leave my web inactive for a while

"Response.Redirect.cannot be called in a Page callback."

I'm storing the user ids in session and during page load I check to see if the user id exists if not then I redirect them to the login page.

I am using devexpress controls, How can I get the redirect to work?

Upvotes: 5

Views: 20947

Answers (7)

Muhammad Raheel
Muhammad Raheel

Reputation: 21

HttpResponse.RedirectLocation Property on MSDN works for me in same problem

here is the sample code from Msdn

Response.StatusCode = 301;
Response.Status = "301 Moved Permanently";
Response.RedirectLocation = "http://www.newurl.com ";
Response.End();

Upvotes: 2

Mitolo
Mitolo

Reputation: 360

You can use:

string TARGET_URL = ...;
if(Page.IsCallback)
    DevExpress.Web.ASPxClasses.ASPxWebControl.RedirectOnCallback(TARGET_URL);
else
    Response.Redirect(TARGET_URL);

Refer at KA18851 in Devexpress

Upvotes: 1

Fredrik Eder
Fredrik Eder

Reputation: 351

Try using the Response.RedirectLocation property instead which works during callback.

HttpResponse.RedirectLocation Property on MSDN

Upvotes: 7

AYCAN
AYCAN

Reputation: 71

if (Page.IsCallback) ASPxWebControl.RedirectOnCallback("~/Login.aspx");

http://documentation.devexpress.com/#AspNet/DevExpressWebASPxClassesASPxWebControl_RedirectOnCallbacktopic

Upvotes: 7

DevExpress Team
DevExpress Team

Reputation: 11376

Indeed, it is impossible to use the Response.Redirect during a callback. Please refer to the following blog post in this regard.

http://community.devexpress.com/blogs/aspnet/archive/2008/08/25/how-to-redirect-to-login-page-after-session-timeout.aspx

Upvotes: 0

AGoodDisplayName
AGoodDisplayName

Reputation: 5653

You can usually turn callbacks off for devexpress controls like the ASPxGridView using the "EnableCallbacks" property. This will obviously cause the controls to use postbacks, but it will also allow Response.Redirect to do its job.

Upvotes: 2

matt-dot-net
matt-dot-net

Reputation: 4244

You can't get the redirect to work in a callback. Perhaps instead of doing Response.Redirect on the server you could write some value in a <script type="text/javascript"/> block and set the window.location.href (redirect) on the client side?

Upvotes: 1

Related Questions