tags:

views:

288

answers:

3

I have a page with several gridviews. For usability, I have put these gridviews into a series of jquery tabs. Tabs works by creating anchor links that go to containers with certain ids, so after clicking on a given tab, the url might change from

host.com/page.aspx

to

host.com/page.aspx#tab2

The issue is that if any elements inside the tabs cause a postback, like trying to sort or page the grid for example, upon loading, the selected tab is lost, and reverts back to the first tab in the list. So in that case I would have sorted the right grid, but I'd have to click the correct tab again to see it.

To fix the issue, I want to track what anchor I'm at as the postback occurs, so that I can change the url I'm loading to include it. The only way I can think to do it is a Redirect, which I really don't want to incur the cost of.

Is there some better way to specify which anchor to load on postback?

+1  A: 

On the forms onsubmit event, modify the action attribute to include the relevant anchor (which you'll need to keep track of yourself)

JonoW
Perfect solution, good thinking.
Pete Michaud
A: 

If the page is posting back to itself then instead of making the post back to foo.aspx you need to make it postback to foo.aspx#anchor.

You could also do this via cookies if you must but anchors is much better. Cookies are more useful for things like customizing the Yahoo page to focus on a particular tab on each visit.

aleemb
A: 

you can set the Page.MaintainScrollPositionOnPostback = true.

Shiny