Personal Blog of Mustafa Basgun

Rule The Back Button of A Browser by ASP.NET

with one comment

I recently needed to find a way to manage the back button of a browser for one of my applications at the work. I have found some forum entries and blog posts about the subject, but they were all some kind of complex solutions. All I wanted to do was just performing a single line code and redirecting to the main page when the user clicks the back button.

After spending couple of hours, here is the 4-step way that I came up with at the end.

First, assign an ID to the “body” tag in order to be able to call it in the Page_Load event:

Place a hidden HTML button control with an “onserverclick” event inside the page:

Add an “onunload” event (which will force a postback via Button1) to the “body” tag:

Finally, define the “onserverclick” event which was assigned to Button1 before:

Hope this helps!

Advertisements

Written by Mustafa Basgun

January 25, 2008 at 11:00 AM

One Response

Subscribe to comments with RSS.

  1. Working good with IE, but not with Firefox…

    Yaung

    January 25, 2008 at 9:44 PM


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: