Solved

ASP.NET Treeview ViewState not working properly.

Posted on 2006-11-05
9
610 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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 500 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
DLL in ASP.NET 20 56
I need help displaying 2 models in one view in my MVC.Net application with C# code behind 5 30
Json and asp.net mvc 2 43
SQL Exceptions 3 35
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
This is a video describing the growing solar energy use in Utah. This is a topic that greatly interests me and so I decided to produce a video about it.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

932 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now