Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

ASP.NET Treeview ViewState not working properly.

Posted on 2006-11-05
9
Medium Priority
?
670 Views
Last Modified: 2012-06-21
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
Comment
Question by:mxpoint
  • 5
  • 3
9 Comments
 
LVL 12

Expert Comment

by:sandip132
ID: 17878938
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
 
LVL 2

Expert Comment

by:santhoshx
ID: 17879149
In your .asp page add EnableEventValidation="false"  in the @ page directive. Give a try  and find it works
0
 

Author Comment

by:mxpoint
ID: 17881549
I got this error:
Error parsing attribute 'enableeventvalidation': Type 'System.Web.UI.MasterPage' does not have a public property named 'enableeventvalidation'.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 2

Expert Comment

by:santhoshx
ID: 17886907
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
 
LVL 2

Expert Comment

by:santhoshx
ID: 17887092
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
 

Author Comment

by:mxpoint
ID: 17893370
I looked at the above url's and the OnTreeNodeDataBound don't work because I am not binding any data to the treeview.
0
 
LVL 2

Expert Comment

by:santhoshx
ID: 17894964
How do you populate Treeview control. Also from where you get data to populate Treeview. Is it used for Menu Navigation?
0
 

Author Comment

by:mxpoint
ID: 17895008
The treeview is not dynamic. I added them to the treeview in design view. That's why the OnTreeNodeDataBound don't work.
0
 
LVL 2

Accepted Solution

by:
santhoshx earned 2000 total points
ID: 17895350
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

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

885 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question