How to change the Forecolor of the node with web services

10 posts, 1 answers
  1. Todd A
    Todd A avatar
    43 posts
    Member since:
    Sep 2009

    Posted 14 Jul 2010 Link to this post

    Hello,

    I am having an issue defining the forecolor of a dynamic node thorugh a web service.

    By setting the forecolor before rendering the page, it works fine through code.

    When fetching more nodes through the web service, there is no forecolor property to set.

    We use the skin manager.  And I don't want to change the default skin css files since the color change can be user specific.  Also, I only want to change the forecolor for this treeview not all of them on the page.

    Any help would be appreciated.

    Thanks,
    Todd.
  2. Nikolay Tsenkov
    Admin
    Nikolay Tsenkov avatar
    734 posts

    Posted 15 Jul 2010 Link to this post

    Hello Todd A,

    Well, for now we don't serialize data such as fore and background color of the nodes.

    So you can not get it directly from a property.

    What you can do, though, is to set a custom attribute to the node, containing the value of the color. Then on the client you can plug in OnClientNodeDataBound event and get this same attribute's value. After this you have to apply it as a style of the dom element of the node (node.get_element().style...).

    Here is a reference to the client object of the RadTreeNode: http://www.telerik.com/help/aspnet-ajax/tree_clientradtreenode.html
    Here is a reference to the ClientNodeDataBound event: http://www.telerik.com/help/aspnet-ajax/treeview-client-side-events-onclientnodedatabound.html

    We, definitely are going to think about including this as a property of the nodes that are being sent from the server for future development, but for now this should work for you just as fine.

    Hope this is helpful for you!


    Regards,
    Nikolay Tsenkov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. Todd A
    Todd A avatar
    43 posts
    Member since:
    Sep 2009

    Posted 15 Jul 2010 Link to this post

    <script type="text/javascript">  
        function NavOnClientNodeDataBoundHandler(sender, e)  
        {  
            var node = e.get_node();  
            node.set_toolTip(node.get_attributes().getAttribute("ToolTip")); 
            node.get_element().style.color = node.get_attributes().getAttribute("Color");
        }          
    </script>

    Hi Nikolay,

    The above code sets the tooltip no problem.  I've added the code line to update the color.  Although the color does not change.  I tried hardcoding the color attribute to "#ffffff" with no luck either.  If the syntax looks right above, I will try to isolate it to determine if something else is interfering with it.

    Thanks,
    Todd.
  4. Nikolay Tsenkov
    Admin
    Nikolay Tsenkov avatar
    734 posts

    Posted 16 Jul 2010 Link to this post

    Hi Todd A,

    I have just tried this out (setting manually the color on the client side) and it works.

    Your ClientNodeDataBoundHandler looks fine.

    Could you, please, post the whole page and the code-behind creating the nodes that are sent to the client on demand?

    I am sure that we will resolve this soon!


    Regards,
    Nikolay Tsenkov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  5. Todd A
    Todd A avatar
    43 posts
    Member since:
    Sep 2009

    Posted 17 Jul 2010 Link to this post

    Hi Nikolay,

    I have narrowed it down to a single property.  When setting the NavigateUrl on the web service call -- the color is not set.   When I comment the NavigateUrl property, it works just fine.  I have copied the code below.

    We are currently using version:
    Telerik Web UI 2009.3.1208.35

    Any workarounds or suggestions would be greatly appreciated.

    Thanks,
    Todd.

    public partial class Default : System.Web.UI.Page 
    {
        protected void Page_Load(object sender, EventArgs e)
        {
      
            RadPanelItem panelItem = new RadPanelItem();
            panelItem.Text = "Test PanelItem";        
            panelItem.Expanded = true;
            panelItem.PreventCollapse = true;
      
            RadTreeView tree = new RadTreeView();
            tree.EnableViewState = true;
            tree.WebServiceSettings.Path = "~/WebService1.asmx";
            tree.WebServiceSettings.Method = "LoadNodes";
            tree.OnClientNodeDataBound = "NavOnClientNodeDataBoundHandler";
      
            panelItem.Controls.Add(tree);
            NavPanelBar.Items.Add(panelItem);
      
            RadTreeNode testNode = new RadTreeNode();
            testNode.Text = "test node";
            testNode.ForeColor = System.Drawing.ColorTranslator.FromHtml("#FF0000");                       
            testNode.ExpandMode = TreeNodeExpandMode.WebService;
            tree.Nodes.Add(testNode);
      
        }
      
      
    }


    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Default" %>
      
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
      
    <head>
        <title></title>
    </head>
    <body>
      
        <script type="text/javascript">  
            function NavOnClientNodeDataBoundHandler(sender, e)  
            {  
                var node = e.get_node();  
                node.set_toolTip(node.get_attributes().getAttribute("ToolTip")); 
                node.get_element().style.color = node.get_attributes().getAttribute("Color");
            }          
        </script
          
        <form id="form1" runat="server">
          
        
        <telerik:RadScriptManager ID="PageScriptManager" runat="server" ScriptMode="Release" EnablePartialRendering="true"  />  
                 
        <div>    
          <telerik:RadPanelBar runat="server" ID="NavPanelBar" Width="150" >
                <ExpandAnimation Type="None"></ExpandAnimation>
                <CollapseAnimation Type="None"></CollapseAnimation>
                <Items />                                                    
            </telerik:RadPanelBar>                     
                     
        </div>      
          
        </form>
    </body>
    </html>


    namespace TreeNodeForeColor
    {
        /// <summary>
        /// Summary description for WebService1
        /// </summary>
        [WebService(Namespace = "http://tempuri.org/")]
        [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
        [System.Web.Script.Services.ScriptService]
        public class WebService1 : System.Web.Services.WebService
        {
      
            [WebMethod(EnableSession = false)]
            public RadTreeNodeData[] LoadNodes(RadTreeNodeData node, object context)
            {
                List<RadTreeNodeData> result = new List<RadTreeNodeData>();
      
                RadTreeNodeData childNode = new RadTreeNodeData();
      
                childNode.Text = "test child";
                childNode.Attributes.Add("ToolTip", "test tooltip");
                childNode.Attributes.Add("Color", "#FF0000");
                //Comment this line and the color is set properly.
                childNode.NavigateUrl = "http://www.yahoo.com";
                result.Add(childNode);
      
                return result.ToArray();
      
            }
        }
      
    }
  6. Answer
    Nikolay Tsenkov
    Admin
    Nikolay Tsenkov avatar
    734 posts

    Posted 21 Jul 2010 Link to this post

    Hi Todd A,

    I have good news for you, I was able to resolve the problem!
    The only thing you need to change is the domElement that's color should be changed.
    Previously you were taking the domElement of the Node ("<li..."), and changing it's color automatically was applied on the text of the node (in case of a standard load rendered as span), but when the nodes are loaded through web service their text is rendered differently (anchors) and the change in the node's domElement color doesn't result in changing the color of the text (currently anchor).
    That's why you need to get the domElement of Node.Text.
    Here is how the JavaScript function looks like:
    function NavOnClientNodeDataBoundHandler(sender,e) {
        var node=e.get_node();
        node.set_toolTip(node.get_attributes().getAttribute("ToolTip"));
        node.get_textElement().style.color=node.get_attributes().getAttribute("Color");
    }         

    Hope this is going to help you!


    Regards,
    Nikolay Tsenkov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  7. Todd A
    Todd A avatar
    43 posts
    Member since:
    Sep 2009

    Posted 21 Jul 2010 Link to this post

    Hi Nikolay,

    I ended up implementing a workaround without using the NavigateUrl over the weekend.  I put the url in the custom attributes and used the client sIde click event to navigate on a click.  Thus keeping the color by not using NavigateUrl method.  It works, although I'll definately make the change you recommend and use the NavigateUrl property.  I'll confirm once I have it working.

    Thanks for your help -- I appreciate the excellent support you guys provide.

    Thanks,
    Todd.
  8. Todd A
    Todd A avatar
    43 posts
    Member since:
    Sep 2009

    Posted 22 Jul 2010 Link to this post

    Hi Nikolay,

    That did the trick!  I removed my workaround for the NavigateUrl not working --- and replaced with your code below.

    node.get_textElement().style.color=node.get_attributes().getAttribute("Color");

    Thanks,
    Todd.
  9. Nikolay Tsenkov
    Admin
    Nikolay Tsenkov avatar
    734 posts

    Posted 23 Jul 2010 Link to this post

    Hello Todd,

    You are welcome!

    Hope that you will not experience any more hard times with our controls, but if you do, though, you can count on our help!


    Regards,
    Nikolay Tsenkov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  10. Cristopher
    Cristopher avatar
    1 posts
    Member since:
    Nov 2010

    Posted 16 Nov 2010 Link to this post

    I am using vb richtextbox, I have to highlight a particular line in runtime. I am able to give the line numbers in runtime. I need the code to change the forecolor when the corresponding line number was given in runtime.

    contractors bond
Back to Top