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?
mxpointAsked:
Who is Participating?
 
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
 
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
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

 
mxpointAuthor Commented:
I got this error:
Error parsing attribute 'enableeventvalidation': Type 'System.Web.UI.MasterPage' does not have a public property named 'enableeventvalidation'.
0
 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.