3

I would like to try and use jQuery UI along side of master pages in ASP.Net 4.0; I like the widgets better than the .Net controls. But I have a question around the accordion control.

Is it possible to put an accordion control in the master page and use it like a menu and still allow it to retain it's selected panel? In other words, each time a page is loaded, the ready() event triggers in the master page and resets the accordion. If I have panel 3 open, and select an item in the panel, I would like panel 3 to remain open when the new content is loaded.

I was thinking I only want to to the jQuery ready function on the initial load of the master page but I can't seem to make that happen.

I hope this makes sense.

Thank you

5 Answers 5

2

Apparently you are not alone having this issue and most people are doing it the way this post explains it.

Sign up to request clarification or add additional context in comments.

1 Comment

I hate to use cookies like @mikemanne mentions but this solution does work.
1

You could use an asp:Hidden field to hold the "currentOpenAccordionPanel". I'm sure there's a jQuery event you can hook to update that field whenever a different panel is opened. Then your page-init code can check that field and open that panel (or open a default panel if that field is empty or absent).

Because its an asp:Hidden field, the value will remain stable through postback operations (it will live in the viewstate), which is what it sounds like you wanted.

I like this approach a little better than a Session-based approach or cookie-based approach: if a user has multiple browsers/tabs open on your site, they will stomp each other's values if you store the value in a common location (like session or cookie). Viewstate-stored data will still behave fine if the user has multiple tabs open.

2 Comments

Hi Mike. Thank you for your help. I get what you suggest but I can't get the hidden field to work as you suggest. Once I navigate to a different page, the hidden field gets reset. That is, the reference to it in the master page resets it back to it's default value.
Agreed - like all viewstate-stored data, it persists through postbacks, but not through new page requests. I misunderstood your question - I didn't realize you wanted the same accordion panel's open item to persist through the user's entire session on the website (or in the case of cookie-based data storage, multiple sessions).
0

I'm not sure if this is a great answer or not, but you can probably use session variables and logic in the view to only render the accordion script on the first load. Set a session var to something, and check for that value on subsequent loads. If it's set, don't render the javascript code (?) There might be a better way.

Comments

0
  1. Make a "Content area" iframe. When a link on the accordian is clicked, load a different page in the iframe.

  2. or make a content area div, and on the accordian link click, make an ajax call to and load the new content there

Comments

0

Do you have to do full page postbacks? If not then you could use ajax from the client to interact with the server and avoid having to keep the accordian's state. Using the UpdatePanel is 1 option for this. Also, you could add a hidden input field to the form and set its value prior to posting back. Then on the server you can use ClientScriptManager to emit the necessary jQuery call to set the accordian's state back to what it was before the postback.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.