2
votes

I am implementing a web based system. I need to capture if the back button of browser is pressed. It doesnt postback if the back button is pressed. I have seen some code parts but it doesnt solve my problem. I have a home page. I want to postback my homepage if the back button of browser is clicked.

Well to be more clear-> Home page-> x.aspx?Date=30.01.2012 , I put the date to the session, then the back button of browser,Home page ???? There I want to get the date from the session by postbacking the home page.

window.history.go(-1) 
4
I don't think this is possible... - Holger

4 Answers

2
votes

This is not an easy problem to solve for a few reasons:

  • Caching behaves differently on different browsers
  • You are going to be interfering with natural UI interaction which is ill advised
  • It's probably a design problem

I wouldn't attempt this for those reasons, and would instead look at the problem from a different angle (for example, is it a design problem?)

For what it's worth I think this is possible to a certain level but it would be an overly complex solution for the task it's trying to solve and very difficult to debug/maintain in the future.

0
votes

I am guessing that you are trying to avoid the case where a user goes back and resubmits a form. You can avoid having to detect the use of the back button by using the POST/REDIRECT/GET (PRG) pattern instead. After handling the form submission, do a redirect to the page you would like to be on.

0
votes

You can try using ScriptManager with the EnableHistory property set to true.

<asp:ScriptManager ID="ScriptManager1" runat="server"
    EnableHistory="true" />

An article on MSDN describing this: http://msdn.microsoft.com/en-us/library/ie/cc488548.aspx

0
votes

If you want to disable back button on one of the page try using below javascript

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

& in your body tag write below

<BODY onload="noBack();" onpageshow="if (event.persisted) noBack();" onunload="">

This should surely solve your problem.

Happy Coding !!