Reputation: 3883
I have pages "first.aspx" and "second.aspx". Now from first.aspx, using link button I'm doing " Response.Redirect()" to "Third.aspx" and simlarly from second.aspx also with link button I'm doing " Response.Redirect() to "Third.aspx". but I want to disable a button on "third.aspx" when I come from " first.aspx" only . how can i acheive this.
Upvotes: 1
Views: 750
Reputation: 37543
I like @Justin Niessner's response, but an alternative method would be instead of using a Response.Redirect
to use the PostBackUrl
property of the button in question. This would cause the page to "post" to the third.aspx page, and from there you would have access to `Page.PreviousPage'. More information on Previous page can be found on MSDN.
http://msdn.microsoft.com/en-us/library/system.web.ui.page.previouspage.aspx
Edit:
A bonus to using the PostBackUrl
property is that it will invoke the standard .Net validation controls and will help prevent the spoofing mentioned by @Jan. It doesn't make it impossible, but it certainly makes it more difficult.
Upvotes: 0
Reputation: 3524
Add a query parameter to indicate which page you came from:
Response.Redirect('third.aspx?referrer=first');
and
Response.Redirect('third.aspx?referrer=second');
in third:
if (Request["referrer"] == "first"){
button.Enabled = false;
}
Upvotes: 0
Reputation: 65294
When coming from first.aspx redirect to Third.aspx?from=first, when coming from second.aspx redirect to Third.aspx?from=second, then use the get parameter to disable/enable your button
Upvotes: 0
Reputation: 16038
You can check the referrer of the request, but that might get spoofed:
Request.UrlReferrer
Or you can pass an url parameter.
Or if you don't want to rely on client side parameter passing, you can save the last page in the users session on the server and check that in your third.aspx page.
Upvotes: 1
Reputation: 245439
You could try using:
var enabled = Page.Request.UrlReferrer.ToString().Contains("first.aspx");
Upvotes: 1