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

Find dynamically created Control

4 Answers 117 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Chris Salas
Top achievements
Rank 1
Chris Salas asked on 16 Jan 2012, 10:12 PM


Posted 11 minutes ago (permalink)

I have the following aspx code in a usercontrol:

<telerik:RadTabStrip ID="radTSCapabilities" runat="server" SelectedIndex="0" Skin="Default" MultiPageID="radMPCapabilities" />
    <telerik:RadMultiPage ID="radMPCapabilities" runat="server" SelectedIndex="0" />

I dynamically create the Tabs and PageViews from the code behind on load.  Inside the PageView is a RadTreeView.  See code below:
Telerik.Web.UI.RadPageView tmpPageView = new Telerik.Web.UI.RadPageView();
tmpPageView.ID = type.AbilityType.Name;
radMPCapabilities.PageViews.Add(tmpPageView);
 
//Add a Tab for the AbilityType
Telerik.Web.UI.RadTab tmpTab = new Telerik.Web.UI.RadTab(type.AbilityType.Name, type.AbilityType.ID.ToString());
tmpTab.PageViewID = tmpPageView.ID;
radTSCapabilities.Tabs.Add(tmpTab);
 
//Create and Load the Rad Tree
Telerik.Web.UI.RadTreeView radTree = new Telerik.Web.UI.RadTreeView();
radTree.Skin = "Default";
radTree.CheckBoxes = true;
radTree.TriStateCheckBoxes = true;
radTree.CheckChildNodes = true;
radTree.NodeDataBound += new Telerik.Web.UI.RadTreeViewEventHandler(radTree_NodeDataBound);
radTree.ID = type.AbilityType.ID.ToString() + type.AbilityType.Name.Replace(" ""_");
radTree.DataTextField = "Name";
radTree.DataValueField = "ID";
radTree.DataFieldID = "ID";
radTree.DataFieldParentID = "ParentID";
 
//If there are multiple Ability Types in result set then go to the DB to get all Abilities for that type
if (distinctAbilityTypes.Count() != 1)
    radTree.DataSource = AbilityMgr.GetAbilitiesByAbilityTypeID(type.AbilityType.ID);
else
    radTree.DataSource = tmpAbilities;
 
//Bind the Tree
radTree.DataBind();
 
//Add a top border
Literal tmpLiteral = new Literal();
tmpLiteral.Text = "<div style='border-top:solid 1px #AAAAAA;'></div>";
 
//Add the Literal and Tree to the associated PageView
radMPCapabilities.FindControl(type.AbilityType.Name).Controls.Add(tmpLiteral);
radMPCapabilities.FindControl(type.AbilityType.Name).Controls.Add(radTree);

I am trying to get a reference to the dynamically created RadTreeView.  I have been unable to do so for some time now.  Please help.

4 Answers, 1 is accepted

Sort by
0
Chris Salas
Top achievements
Rank 1
answered on 17 Jan 2012, 08:03 PM
Anyone?  After more research I found that I cannot find any of my dynamically generated RadTreeViews.  Is this by design?  I have iterated through all the controls on the page at load and have not been able to get reference to any of them.  HELP PLEASE!!!
0
Chris Salas
Top achievements
Rank 1
answered on 17 Jan 2012, 09:57 PM
Ok, more info.  The issues here, im pretty sure, is that because of the post back event of a save button click the controls are being removed.  This seems like a small issue, however I cant seem to figure this out.  The TreeView that I am trying to reference has checkboxes and i need to be able to cycle through those checkboxes and get the selected nodes.  The listing is a Lab Capabilities taxonomy and the selections are going to be stored into a db.
0
Plamen
Telerik team
answered on 19 Jan 2012, 01:10 PM
Hi Chris,

 
I am sending you a sample project that shows one way how to get the selected node of the Tree that is added dynamically. You can also refer to the help topic about the client object of the RadTreeView.

Hope this will be helpful.

Greetings,

Plamen Zdravkov
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
0
Chris Salas
Top achievements
Rank 1
answered on 19 Jan 2012, 02:43 PM
Thank you for the demo project, however last night i figured out a resolution to my issue.  I turned off the ViewState and i was able to access the controls.  I am not 100% sure why this corrected the issue, but it did.
Tags
TreeView
Asked by
Chris Salas
Top achievements
Rank 1
Answers by
Chris Salas
Top achievements
Rank 1
Plamen
Telerik team
Share this question
or