Howto change the forecolor of a node client-side

7 posts, 1 answers
  1. Tobias
    Tobias avatar
    12 posts
    Member since:
    Dec 2008

    Posted 28 Dec 2009 Link to this post


    I'm trying to change the ForeColor of a node client side. I have managed to do this by altering the innerHTML but this has ugly side effects. Do anyone have a better way?

    What I really want to do is to change a node from dimgray to the original color determined by the skin. 

    Best Regards
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 29 Dec 2009 Link to this post

    Hello Daniel,

    Try the following code in order to change the forecolor of node from client side.

        function changeColor() { 
            var tree = $find('<%= RadTreeView1.ClientID %>'); 
            var node = tree.findNodeByText('Root RadTreeNode1'); // get the node 
            node.get_element().style.color = "red"// change the color 

  3. Tobias
    Tobias avatar
    12 posts
    Member since:
    Dec 2008

    Posted 29 Dec 2009 Link to this post

    Hi again,

    thanks for the help but it didn't work.

    I set the forecolor from code behind to illustrate that a node is deleted. The complete code to change the color is below according to your sample. It is in the rightclick meny of a context menu. I have investigated the complete style property and it is completly empty. It contains a lot of properties but all is either "", 0 or false.

                function ClientContextMenuItemClicked(sender, eventArgs) {  
                    var node = eventArgs.get_node();  
                    var item = eventArgs.get_menuItem();  
                    var menu = item.get_menu();  
                    var command = item.get_attributes().getAttribute("Command");  
                    switch (command) {  
                        case "Undelete":  
                            //Set the color according to style (remove dimgray color)  
                            node.get_element().style.color = "red"//Test  

    Best Regards
  4. Answer
    T. Tsonev
    T. Tsonev avatar
    2834 posts

    Posted 29 Dec 2009 Link to this post


    The ForeColor is applied on the text element (rtIn). To clear it use the following code:

    node.get_textElement().style.color = ""; // Clear ForeColor

    Happy holidays!

    Tsvetomir Tsonev
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  5. Tobias
    Tobias avatar
    12 posts
    Member since:
    Dec 2008

    Posted 29 Dec 2009 Link to this post


    It worked perfektly.

    Have a great New Year!
  6. Igor
    Igor avatar
    12 posts
    Member since:
    Dec 2010

    Posted 02 Feb 2011 Link to this post


    I'm having similar problem. I'm using function bellow to and new treenode, the function is beeing called by RadWindow OnClientClose event.

    function AddNode(args) {
           // Get tree view object
           treeView = $find(args.TreeViewID);
           //Instantiate a new client node
           var node = new Telerik.Web.UI.RadTreeNode();
           //Set node text
           //Set node value
           //Set enable Context Menu
           //Set context menu id      
            node.get_textElement().style.color = "gray";
           //Set allow edit
           //Set allow drag
           //Add the new node as the child of the selected node or the tree view if no node is selected
           var   parent = parent = treeView.findNodeByValue(args.ParentID);
           //Expand the parent if it is not the tree view
           if (parent != treeView && !parent.get_expanded())
           return false;

    when i debug and examine node.get_textElement() the value is alway null
    I have also tried  node.get_element().style.color = "gray";

    Any help will be appreciated.
  7. Yana
    Yana avatar
    5025 posts

    Posted 04 Feb 2011 Link to this post

    Hi Igor,

    Could you please tell us whether you're using templates? Can you send us the definition of the treeview?

    Kind regards,
    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.
Back to Top