Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

ASP.NET Treeview ViewState not working properly.

Posted on 2006-11-05
9
Medium Priority
?
654 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: 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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

664 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