Benk
Benk

Reputation: 1312

asp.net TreeView -keep the same state after postback

I have a TreeView

<asp:TreeView ID="tvCategories"   runat="server" ShowLines="false"  ShowExpandCollapse="true"  ExpandDepth="0"   />

by default the list is not expended. It has a plus symbol (+) to expand the sub nodes.

when i expand the sub node and click on the sub node to show the content. once it shows the content the TreeView goes back to default state (collapses).

How do I make it stay as it was before clicking on the sub node.... expended? (keep the same state after postback)? Thanks

Upvotes: 1

Views: 4546

Answers (2)

hyun
hyun

Reputation: 11

I post a little late but i had the same problem and i find a solution more easy:

  1. ViewStateMode="Enabled" in the Tree View
  2. Fill the TV only if !postback

Hope that help :-)

Upvotes: 1

Gagan
Gagan

Reputation: 5656

what you need to do , is to persist the state of the treeview. Your state is lost as soon as the request is made. In order to persist the state of the treeview you can use one of the following

  1. Session
  2. Cookies
  3. ViewState.

so you need to do

1: Save the treeviewstate

2: Redirect

and in exactly the same order

Upvotes: 1

Related Questions