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

Getting data from dynamically added control inside RadTreeView

1 Answer 38 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Alexander
Top achievements
Rank 1
Alexander asked on 19 Dec 2012, 03:27 PM
Hi
I have a dynamically added UserControl inside my RadTreeView. During a serverside event, I need to get the control to extract the data inside, but I cannot seem to find the control. The binding is executed both on post and postback.

This is the binding of the control:
foreach (Event item in eventList)
{
    RadTreeNode rootNode = new RadTreeNode(item.Name, item.Id.ToString());
    rootNode.Expanded = true;
    RadTreeNode childNode = new RadTreeNode();
 
    ActorNode actorNode = (ActorNode)LoadControl("ComponentControls/ActorNode.ascx");
    actorNode.ID = ACTOR_NODE_ID + item.Id;
 
    List<Actor> actorList = Actor.GetActorList(item.Id);
    List<MunicipalityActor> munActorList = MunicipalityActor.GetMunActorList(MunCode);
 
    actorNode.InitializeControl(municipalityActorList, actorList);
 
    childNode.Controls.Add(actorNode);
    rootNode.Nodes.Add(childNode);
 
    RadTreeView_Actors.Nodes.Add(rootNode);
}

This is the serverside event, where I am trying to get hold of the data...
foreach (RadTreeNode rootNode in RadTreeView_Actors.Nodes)
{
    Control control = rootNode.Nodes[0].FindControl(ACTOR_NODE_ID + rootNode.Value);
}

Is the control-id not what i set it to?

1 Answer, 1 is accepted

Sort by
0
Bozhidar
Telerik team
answered on 24 Dec 2012, 07:41 AM
Hello Alexander,

From the provided code it's not clear when exactly you are adding the user control to the nodes. The user control needs to be added every time the page is posted back. Could you provide some more code, so that we can get a better understanding of the timeline and the sequence of events that take place here.

Also, you can easily check if the problem is the ID - just try to find the control immediately after you add it to the Node.
childNode.Controls.Add(actorNode);
Control control = childNode.FindControls(ACTOR_NODE_ID + item.Id);

 
All the best,
Bozhidar
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
TreeView
Asked by
Alexander
Top achievements
Rank 1
Answers by
Bozhidar
Telerik team
Share this question
or