views:

32

answers:

1

On an ASP.NET page with a tabstrip, I'm using the hash code in the URL to keep track of what tab I'm on (using the BBQ jQuery plugin). For example:

http://mysite.com/foo/home#tab=budget

Unfortunately, I've just realized that there are a couple of places on the page where I'm using an old-fashioned ASP.NET postback to do stuff, and when the postback is complete, the hash is gone:

http://mysite.com/foo/home

... so I'm whisked away to a different tab. No good.

This is a webforms site (not MVC) using .NET 4.0. As you can see, though, I am using URL routing.

Is there a way to tell ASP.NET to keep the hash in the URL following a postback?

+1  A: 

The problem is that the postback goes to the url of the current page, which is set in the action of the form on the page. By default this url is without #hash in asp.net, and its automatically set by asp.net, you have no control over it.

You could add the #hash to the forms action attribute with javascript:

document.getElementById("aspnetForm").action += location.hash

just make sure you execute this code on window.load and you target the right ID

Willem
Thanks, I'll give that a try.
Herb Caudill