0

Here is my code:

protected void btnresult_Click(Object sender, EventArgs e)
{
   Button btn = (Button)(sender);
   Response.Write("<script>");
   Response.Write("window.open('studentresult.aspx?id=" + btn.CommandArgument + "','_blank')");
   Response.Write("</script>");
}

My home page studententry.aspx

In my home page, when I click result button, it goes to new window page and it shows student result.

But after that I will take a look at home page, it shows back button on the top of url address bar.

So I click the back button, again it goes to new window page and shows student result.

May I know, why the back button is active when I click result button?

Vogel612
  • 5,620
  • 5
  • 48
  • 73
pcs
  • 1,864
  • 4
  • 25
  • 49
  • above code is targeting blank so its opening new tab of browser, so when you open new tab its back button is disabled by default This might guide you http://stackoverflow.com/a/19971975/3583859 – Vijay Kumbhoje Dec 09 '15 at 11:48
  • In new tab is disabled by default.. but in my home getting enable back button right... – pcs Dec 09 '15 at 12:11
  • try link in above comment, it might help you – Vijay Kumbhoje Dec 09 '15 at 12:12
  • @VijayKumbhoje: actually i m struggling how to add code in my existing code from your link.. – pcs Dec 09 '15 at 12:27

1 Answers1

0

Write below method on your page code behind file and call it on page load event.

public void disablebrowserbackbutton()
{
 HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);
 HttpContext.Current.Response.Cache.SetNoServerCaching();
 HttpContext.Current.Response.Cache.SetNoStore();
}

Add below Script in your client side file (html) inside <head> tag or if you using Masterpages before contentPlaceHolder

<script type="text/javascript">
function preventBack() {
    window.history.forward();
}
setTimeout("preventBack()", 0);
window.onunload = function() {
    null
};

Vijay Kumbhoje
  • 1,401
  • 2
  • 25
  • 44