I am trying to disable the back button from code behind in asp.net. I already know how to do it in javascript. I have the following code in my page_init method, but I can still see the back button enabled in chrome:
As far as I think,your requirment is impossible.It will not work if the forward page does not exist in the history list.So,disabling browser caching in code behind could prevent users navigate back to another page by using browser back button,however,it
couldn't disable the back button.
I suggest you could do this is to pass a token on every URL within the application, and within every form. The token is regenerated on every page, and once the user loads a new page any tokens from previous pages are invalidated.When the user loads a page,
the page will only show if the correct token (which was given to all links/forms on the previous page) was passed to it.
Another way is this by server-side tracking of the user session, and redirecting (as in Server.Transfer, not Response.Redirect) the user/browser to the required page.
.NET forums are moving to a new home on Microsoft Q&A, we encourage you to go to Microsoft Q&A for .NET for posting new questions and get involved today.
Member
511 Points
1275 Posts
disable the back button from code behind in asp.net
Jul 15, 2020 01:43 PM|anjaliagarwal5@yahoo.com|LINK
<div class="post-text" itemprop="text">
I am trying to disable the back button from code behind in asp.net. I already know how to do it in javascript. I have the following code in my page_init method, but I can still see the back button enabled in chrome:
I want the button to be disabled so that the user cannot click on it.
All-Star
53081 Points
23655 Posts
Re: disable the back button from code behind in asp.net
Jul 15, 2020 01:50 PM|mgebhard|LINK
It's not possible to disable the back button. You can remove/modify the history using JavaScript though.
https://developer.mozilla.org/en-US/docs/Web/API/History_API
Usually the Post/Redirect/Get pattern solves this issue.
https://en.wikipedia.org/wiki/Post/Redirect/Get#:~:text=Post%2FRedirect%2FGet%20(PRG,submitting%20the%20form%20another%20time.
Contributor
3730 Points
1431 Posts
Re: disable the back button from code behind in asp.net
Jul 16, 2020 06:19 AM|yij sun|LINK
Hi anjaliagarwal5@yahoo.com,
As far as I think,your requirment is impossible.It will not work if the forward page does not exist in the history list.So,disabling browser caching in code behind could prevent users navigate back to another page by using browser back button,however,it couldn't disable the back button.
I suggest you could do this is to pass a token on every URL within the application, and within every form. The token is regenerated on every page, and once the user loads a new page any tokens from previous pages are invalidated.When the user loads a page, the page will only show if the correct token (which was given to all links/forms on the previous page) was passed to it.
Another way is this by server-side tracking of the user session, and redirecting (as in Server.Transfer, not Response.Redirect) the user/browser to the required page.
More details,you could refer to below article:
https://stackoverflow.com/questions/961188/disable-browsers-back-button
https://www.codeproject.com/Questions/732138/disable-back-button-in-asp-net-using-csharp
Best regards,
Yijing Sun