This is a migrated thread and some comments may be shown as answers.

Custom RadTreeNode missing during PostBack Event

4 Answers 166 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Polymorphic Solutions
Top achievements
Rank 1
Polymorphic Solutions asked on 22 Feb 2010, 07:17 AM
Hi,

I just tried to populate the RadTreeView control dynamically from code behind using a custom user control added to each Node item and I am curious with the non-persistence state of the Node item data during the Page PostBack. My Node item seems to keep missing from the TreeView everytime the Page is posting back.

For background information, I did not use the DataBinding method and had to manually added the Node item into the TreeView as the database structure that I had does not have the parent-child relationship defined in one table, instead I have to go to three different database tables to link them together in order to get the parent-child relationship for building the TreeView.

I've set the EnableViewState properties of both the RadTreeView and every node item contained in that TreeView but the node item still keep missing. I can repopulate the node item in the TreeView every PostBack event to keep the Node item there, but that means I will loose the event information especially the Drag-N-Drop event.

The situation does not happen if I don't use the custom user control, but I will need the custom control as the standard Node item style does not suit my needs.

Is there anything that you can suggest to me to solve this issue?

Regards

4 Answers, 1 is accepted

Sort by
0
Yana
Telerik team
answered on 24 Feb 2010, 01:26 PM
Hello Mark,

You should only add the custom control on every postback, not the whole node - in this way the events will be fired as expected. I suggest you set some Value to this node and then use this Value to find it and add the control to it.

If you have any difficulties with the approach, please write to us again.

Kind regards,
Yana
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Steven Lugovsky
Top achievements
Rank 1
answered on 14 Apr 2010, 07:00 PM
Out of curiousity - how did you accomplish this in the end? In which event did you readd the control to the node?

Im trying to accomplish something similar and have noticed that if I add the control to the PageLoad event, I lose the viewstate.  If I try to add it to OnInit, the node isnt accessible yet so you have to add another node...

thanks!

Steve Lugovsky

*EDIT* Nevermind ! this *does* work in the Page_load, my control ID was a victim of the ol' off-by-one error :P

Cheers!
0
Chief
Top achievements
Rank 1
answered on 02 Jun 2011, 10:09 AM
Can you give a specific example about this issue?

i tried to add template control

with
NodeTemplate template = new NodeTemplate(item.Description.Trim().Substring(0, 5), true);                template.InstantiateIn(node);
 
 
class NodeTemplate : ITemplate
        {
            private string binder;
            private bool flag;
            public NodeTemplate(string binder, bool flag)
            {
                this.binder = binder;
                this.flag = flag;
            }
            public void InstantiateIn(Control container)
            {
                Literal ltr = new Literal();
                ltr.ID = "ltr";
                if (flag)
                {
                    ltr.Text = @"<Font color='Red' size='3px'>" + binder + "..." + "</Font>";
                }
                else
                {
                    ltr.Text = @"<Font color='Black'>" + binder + "..." + "</Font>";
                }
                //ltr.DataBinding += new EventHandler(label1_DataBinding);
                container.Controls.Add(ltr);
            }
}

in the page load. but after postback loosing text inside literal.... actually loosing literal
0
Plamen
Telerik team
answered on 07 Jun 2011, 12:33 PM
Hello bülent,

Try to do your logic in Page_Init instead in Page_Load.

You can see a simple example at one of our help topics:
http://www.telerik.com/help/aspnet-ajax/treeview-templates-runtime.html.

Greetings,
Plamen Zdravkov
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

Tags
TreeView
Asked by
Polymorphic Solutions
Top achievements
Rank 1
Answers by
Yana
Telerik team
Steven Lugovsky
Top achievements
Rank 1
Chief
Top achievements
Rank 1
Plamen
Telerik team
Share this question
or