I have an asp.net (C#) project in VS 2013 in which I load a form SelectFromWeb from an ASP button from another form. I would like to disable the Back button on SelectFromWeb or trap the click on the Back button.
I tried adding the following code to the Page_Load event in SelectFromWeb
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetExpires(DateTime.UtcNow.AddHours(-1));
Response.Cache.SetNoStore();
But the Back button was still shown in Chrome and Firefox.
I tried to trap the click on the back button by creatin a dedicated Master page for SelectFromWeb and replacing the <body> tag in the form markup with the following code:
<body onbeforeunload="HandleBackFunctionality()">
function HandleBackFunctionality()
{
if(window.event) //Internet Explorer
{
alert("Browser back button is clicked on Internet Explorer...");
}
else //Other browsers e.g. Chrome
{
alert("Browser back button is clicked on other browser...");
}
}
No alert was shown when the back button was clicked.
Can anyone provide a method either disabling the back button or being able to trap a click on the Back button in an aspx form in an ASP.Net Forms project?