Click here to Skip to main content
15,884,237 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi,

i am using .net 4.0, and i create a web site but here when we press in back space button in keybord to edit a text, i loss in my current page and go to any other page or a home page, i am not understand how i resolve this problem,
Posted

1 solution

We can also achieve this by disabling browser caching in code behind write the following lines of code in Page_Init event or Page_Load event and don’t forgot to add namespace using System.Web; because HttpCacheability related to that namespace


XML
protected void Page_Init(object sender, EventArgs e)
{
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetExpires(DateTime.Now.AddSeconds(-1));
Response.Cache.SetNoStore();
}


We need to place this code in a page wherever we need to disable browser back button. If we use above caching method to disable browser back button that will display webpage expired message like this

------------------------------ OR ------------------------------------------------




<script type = "text/javascript" >

function preventBack(){window.history.forward();}

setTimeout("preventBack()", 0);

window.onunload=function(){null};

</script>


I have tested the script in the following browsers

1. Internet Explorer 5.55

2. Internet Explorer 6

3. Internet Explorer 7

4. Mozilla Firefox 3

5. Opera 9

6. Safari 4

7. Google Chrome
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900