You must Sign In to post a response.
  • Category: ASP.NET

    Disable browser's back button without disturbing page buttonclick event

    My website have lot of pages.I am redirecting user from page1 to page2 onclick of button of page1.I don't want user, to use browser's back button of page2 to come on page1.I searched lot.I got code.I wrote following code in page1.I did not understand code properly

    <script language="Javascript" type="text/javascript">

    function preventBack() { window.history.forward(); }
    setTimeout("preventBack()", 0);
    window.onunload = function () { null };

    </script>
    setTimeout("preventBack()", 0);means call preventBack() function on delay of 0 second.I have one doubt,does function get call everytime.Means continous..what does it means window.onunload = function () { null };?Page2 have button control called clear,when user click on it,user suppose to go page1.But after adding this code ,it does not work.User is not redirecting to page1,it remain on page2 only.How to handle that?

    function preventBack() { window.history.forward(); }
    setTimeout("preventBack()", 0);
    Does it equivalent to

    function preventBack() { window.history.forward(); }
    <body onload="preventBack()">
  • #765371
    Hi Pinky,

    When you want to Redirect to Page1? When you perform some action like button click that time you want to redirect to another page right? then on click event of back button write code for redirecting to page1. What problem have you faced to implement the same. You just explore more. If you have doubts then refer below sample code.


    Protected void btnBack_Click(object sender, EventArgs e)
    {
    Response.Redirect("Page1.aspx");
    }


    Hope this will helpful to you...

    --------------------------------------------------------------------------------
    Give respect to your work, Instead of trying to impress your boss.

    N@veen
    Blog : http://naveens-dotnet.blogspot.in/


Sign In to post your comments