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

    Hi,

    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
    Daniel
  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.

    javascript:
     
        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 
        } 

    -Shinu.
  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  
                            node.set_contextMenuID('m_RadTreeViewContextMenuAdd');  
                            break;  
                    }  
                } 

    Best Regards
    Daniel
  4. Answer
    T. Tsonev
    Admin
    T. Tsonev avatar
    2811 posts

    Posted 29 Dec 2009 Link to this post

    Hello,

    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!

    Greetings,
    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

    Thanks,

    It worked perfektly.

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

    Posted 02 Feb 2011 Link to this post

    Hello

    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);
           treeView.trackChanges();
     
           //Instantiate a new client node
           var node = new Telerik.Web.UI.RadTreeNode();
           //Set node text
           node.set_text(args.NodeName);
           //Set node value
           node.set_value(args.NodeValue);
           //Set enable Context Menu
           node.set_enableContextMenu(true);
           //Set context menu id      
            node.set_contextMenuID("AddEditDeleteDisableContexMenu")       
     
            node.get_textElement().style.color = "gray";
     
           //Set allow edit
           node.set_allowEdit(true)
           //Set allow drag
           node.set_allowDrag(false)
     
           //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);
     
           parent.get_nodes().add(node);
           //Expand the parent if it is not the tree view
           if (parent != treeView && !parent.get_expanded())
               parent.set_expanded(true);
     
           treeView.commitChanges();
     
           node.select();
     
           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
    Admin
    Yana avatar
    4795 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,
    Yana
    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