Reputation: 51
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
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
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
Reputation: 351
Try using the Response.RedirectLocation
property instead which works during callback.
HttpResponse.RedirectLocation Property on MSDN
Upvotes: 7
Reputation: 71
if (Page.IsCallback) ASPxWebControl.RedirectOnCallback("~/Login.aspx");
Upvotes: 7
Reputation: 11376
Indeed, it is impossible to use the Response.Redirect during a callback. Please refer to the following blog post in this regard.
Upvotes: 0
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
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