Getting data from dynamically added control inside RadTreeView

2 posts, 0 answers
  1. Alexander
    Alexander avatar
    31 posts
    Member since:
    Mar 2012

    Posted 19 Dec 2012 Link to this post

    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);

    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?

  2. Bozhidar
    Bozhidar avatar
    1142 posts

    Posted 24 Dec 2012 Link to this post

    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.
    Control control = childNode.FindControls(ACTOR_NODE_ID + item.Id);

    All the best,
    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.
Back to Top