Enable Disable Child Controls

2 posts, 0 answers
  1. Thomas Kristensen
    Thomas Kristensen avatar
    20 posts
    Member since:
    Feb 2006

    Posted 16 Apr 2009 Link to this post


    I am having a case, we want to disable, enable child controls client side  that have been added to a tree node server side.

    However using the javascript enable & disable function of the node only works for the node itself, and not its childs, as it is the case for server side. How does one set this property for a child control to a treenode?
    For example if I have added a combobox to a tree node and want to disable that combo on the client. I have tried playing around with the get_element, however I cannot get it to work. I cannot use the client side Findcontrol, as I do not know the Id of the child control, I want to loop through the collection of child controls to a node and enable/disable using javascript on the client.

    I Hope someone got an idea of how to do this

  2. Simon
    Simon avatar
    2281 posts

    Posted 20 Apr 2009 Link to this post

    Hello Thomas Kristensen,

    There are various ways of finding the client-side objects of the Templated controls.

    One possible solution would be to set the client Id of each control in the Template as an attribute to its containing Node. You could use the attribute later to get the client-side object of the respective control and enable/disable it.

    Below is the code of a simple example illustrating this approach:

        <script type="text/javascript">  
            function toggleEnableNodes(enable) {  
                var treeView = $find("<%= RadTreeView1.ClientID %>");  
                var node = treeView.get_nodes().getNode(0);  
                var comboBoxId = node.get_attributes().getAttribute("comboBoxId");  
                var comboBox = $find(comboBoxId);  
                if (enable) {  
                else {  
        <form id="form1" runat="server">  
            <asp:ScriptManager ID="ScriptManager1" runat="server" /> 
                <telerik:RadTreeView ID="RadTreeView1" runat="server"></telerik:RadTreeView> 
                <input type="button" onclick="return toggleEnableNodes(false);" value="disable root node" /> 
                <input type="button" onclick="return toggleEnableNodes(true);" value="enable root node" /> 

    protected void Page_Load(object sender, EventArgs e)  
        RadTreeNode node = new RadTreeNode("root");  
        node.Expanded = true;  
        RadComboBox comboBox = new RadComboBox();  
        comboBox.Items.Add(new RadComboBoxItem("item 1"));  
        comboBox.Items.Add(new RadComboBoxItem("item 2"));  
        comboBox.Items.Add(new RadComboBoxItem("item 3"));  
        node.Attributes["comboBoxId"] = comboBox.ClientID;  
        node = new RadTreeNode("child 1");  
        node = new RadTreeNode("child 2");  

    Kind regards,
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
Back to Top