• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 674
  • Last Modified:

ASP.NET Treeview ViewState not working properly.

Hi have a treeview with about 20 nodes total (4 deep) on a masterpage. I have the viewstate set to true and expand depth set to 0. But for some reason asp.net is not saving the tree's collapsed state. Every time I click on a link the treeview reset itself to default. How can I fix this?
0
mxpoint
Asked:
mxpoint
  • 5
  • 3
1 Solution
 
sandip132Commented:
A possible approach would be to save the text, value or id of the nodes that are expanded and expand them after the treeview is re-bound. You can find the nodes by their text, value or id (FindNodeByText(), FindNodeByValue(), FindNodeById()) and set their Expanded properties to true.

Hope this helps.    
0
 
santhoshxCommented:
In your .asp page add EnableEventValidation="false"  in the @ page directive. Give a try  and find it works
0
 
mxpointAuthor Commented:
I got this error:
Error parsing attribute 'enableeventvalidation': Type 'System.Web.UI.MasterPage' does not have a public property named 'enableeventvalidation'.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
santhoshxCommented:
You have to add that to the asp page and not the master page. (You must be using your master page in asp page ?)
0
 
santhoshxCommented:
I had a look at this and my suggestion will not work. Check this link and it will give a fair idea on how to implement this

http://forums.asp.net/thread/1452175.aspx and
http://forums.asp.net/1453539/ShowThread.aspx
0
 
mxpointAuthor Commented:
I looked at the above url's and the OnTreeNodeDataBound don't work because I am not binding any data to the treeview.
0
 
santhoshxCommented:
How do you populate Treeview control. Also from where you get data to populate Treeview. Is it used for Menu Navigation?
0
 
mxpointAuthor Commented:
The treeview is not dynamic. I added them to the treeview in design view. That's why the OnTreeNodeDataBound don't work.
0
 
santhoshxCommented:
This what i could think about
In TreeNodeCollapsed keep the node value in a session
In reeNodeExpanded Collapse it. But it can go to collapse event agian. So you have to careful in implementing your logic

protected void TreeView1_TreeNodeCollapsed(object sender, TreeNodeEventArgs e)
    {
       add to session here .
    }
    protected void TreeView1_TreeNodeExpanded(object sender, TreeNodeEventArgs e)
    {
        //        if (e.Node.Text == "New Node")
        //{
            // e.Node.Collapse();
        //}
       
    }
}
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 5
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now