Post Back on Web User Control

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

When I leave a page that has a user control and press the back button on my browser I notice that the Page_Load event of the user control doesn't fire unless i do a refresh on the page. Is there a way to fire this event when I hit the back button on the browser? Is this by design?
 
Yes, it's by design in that the Back button is handled stricly within the browser and does not invoke a round-trip to the server. So, there's nothing to cause a server-side page load event to be reised

What can you do? Write a client-side onload event for the window object. In javascript, it would start out like this
<SCRIPT for="window" event="onload">. In that script, you can submit the form. (Something like "document.Form1.submit()" ). That will cause a postback to occur

The only question is: How to make sure that the window onload event is not raised when the page is first loaded? You'll need to check the content of some element on your page that you know will be different, depending on whether the page was freshly loaded or not. I've been known to use a hidden text box for such things but others might have for elegant solutions to offer

HTH
 
Back
Top