Subscribe to Subscribers

Forums » .NET » ASP.NET »

How to prevent Page action when back button click of browser?


Posted Date: 26 Jul 2012      Posted By:: jebamani     Member Level: Gold    Member Rank: 700     Points: 3   Responses: 6



Hi,
How to prevent page actions when click on back button? for example if page 2 redirected from page 1. now i have clicked the browser back button from page 2 then the page is redirected to page 1. i want to page redirected to the page 1 but never do a actions there. suppose user make any changes on the page 1 the page redirected to the log out page. how it is possible?

Thanks in Advance...




Responses

#682008    Author: saravanakumar      Member Level: Gold      Member Rank: 196     Date: 26/Jul/2012   Rating: 2 out of 52 out of 5     Points: 3

use this script u can disable the back button

<script type="text/javascript" language="javascript">
function disableBackButton() {
window.history.forward()
}
disableBackButton();
window.onload = disableBackButton();
window.onpageshow = function (evt) { if (evt.persisted) disableBackButton() }
window.onunload = function () { void (0) };
</script>


 
#682025    Author: jebamani      Member Level: Gold      Member Rank: 700     Date: 26/Jul/2012   Rating: 2 out of 52 out of 5     Points: 1

Hi,

I dont want to disable back button.

i want to page redirected to the page 1 but never do an actions there. suppose user make any changes on the page 1 the page redirected to the log out page


Thanks in Advance...


 
#682047    Author: Ajatshatru Upadhyay      Member Level: Gold      Member Rank: 17     Date: 26/Jul/2012   Rating: 2 out of 52 out of 5     Points: 2

Hi,

Can you please tell me why do you want to do that?

If the user has already been logged out then he/she can never be able to edit the content of the page, because session has got killed on logout.
User can only edit the content if he/she is still logged in.
In that case why do you want to redirect the user to login page in spite of knowing that he/she is a valid user?

Hope it'll help you.
Regards
Ajatshatru





 
#682048    Author: Ravindran        Member Level: Diamond      Member Rank: 3     Date: 26/Jul/2012   Rating: 2 out of 52 out of 5     Points: 2

Hi,

Use below script under head section of all pages to prevent back button action


<script language="JavaScript" type="text/javascript">
window.history.forward();
</script>


Regards
N.Ravindran
Your Hard work never fails


 
#682094    Author: jebamani      Member Level: Gold      Member Rank: 700     Date: 26/Jul/2012   Rating: 2 out of 52 out of 5     Points: 1

Hi Ajatshatru Upadhyay ,
It is a client requirements. If the user go back by browser back button(user still logged in & user session is available) then the page has to go back but there is no action has to performed on that page. if suppose user click on any button or change the text value that time page is redirected to the log out page. how to solve it?

Thanks in Advance...


 
#682136    Author: Ajatshatru Upadhyay      Member Level: Gold      Member Rank: 17     Date: 27/Jul/2012   Rating: 2 out of 52 out of 5     Points: 4

Hi,

Okay, in that case you can do this with a trick from server side.
Though you can find numerous examples on related issue with JavaScript, but you can never be sure with them. Trying to track the back button click of browser is never being a good idea.
So what you can do is –
On page load of every page create a session object and save anything like page name or any such thing and execute any post back request after validation that session object.


Session[“PageName”] = “some value”;


Now whenever you are redirecting the user to a different page destroy that session object.
This way if user visits the page by clicking back button of the browser, you can easily redirect them to login page, after checking session object for null.

Hope it'll help you.
Regards
Ajatshatru


 
Post Reply
You must Sign In to post a response.

Next : Google bot can not crawl into the site
Previous : How to display dotted short text with asp.net label?
Return to Discussion Forum
Post New Message
Category:

Related Messages

Active Members
TodayLast 7 Daysmore...

Awards & Gifts
Talk to Webmaster Tony John
Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India
2005 - 2013 All Rights Reserved.
.NET and other trademarks mentioned in this site belong to Microsoft and other respective trademark owners.
Articles, tutorials and all other content offered here is for educational purpose only.
We are not associated with Microsoft or its partners.