custom icons (from the famfam stock) don't show up in a TreePanel

  1. #1

    custom icons (from the famfam stock) don't show up in a TreePanel

    To reproduce the problem, go the PageTreeLoader example (under TreePanels) and change the code to set a node icon:

            protected void NodeLoad(object sender, NodeLoadEventArgs e)
            {
                string prefix = e.ExtraParams["prefix"] ?? "";
    
                if (!string.IsNullOrEmpty(e.NodeID))
                {
                    for (int i = 1; i < 6; i++)
                    {
                        AsyncTreeNode asyncNode = new AsyncTreeNode();
                        asyncNode.Text = prefix + e.NodeID + i;
                        asyncNode.NodeID = e.NodeID + i;
                        e.Nodes.Add(asyncNode);
                    }
    
                    for (int i = 6; i < 11; i++)
                    {
                        Ext.Net.TreeNode treeNode = new Ext.Net.TreeNode();
                        treeNode.Text = prefix + e.NodeID + i;
                        treeNode.NodeID = e.NodeID + i;
                        treeNode.Leaf = true;
                      treeNode.Icon = Icon.Note; // Added this line
                        e.Nodes.Add(treeNode);
                    }
                }
            }
    The tree still shows the stock icon.

    I don't understand why you did not define the css styles of for the famfam icons in a css file that can be referenced...
  2. #2
    ok, my bad, this sample works when you add ResourceManager.GetInstance().RegisterIcon(Icon.No te);

    Try the Ajax_Method_Loader sample. Here is the code:
        <script runat="server">
    
            [DirectMethod]
            public static string NodeLoad(string nodeID)
            {
                Ext.Net.TreeNodeCollection nodes = new Ext.Net.TreeNodeCollection();
    
                if (!string.IsNullOrEmpty(nodeID))
                {
                    for (int i = 1; i < 6; i++)
                    {
                        AsyncTreeNode asyncNode = new AsyncTreeNode();
                        asyncNode.Text = nodeID + i;
                        asyncNode.NodeID = nodeID + i;
                        nodes.Add(asyncNode);
                    }
    
                    for (int i = 6; i < 11; i++)
                    { 
                        Ext.Net.TreeNode treeNode = new Ext.Net.TreeNode();
                        treeNode.Text = nodeID + i;
                        treeNode.NodeID = nodeID + i;
                        treeNode.Leaf = true;
                      treeNode.Icon = Icon.Note; // added this
                        ResourceManager.GetInstance().RegisterIcon(Icon.Note); // added this
                        nodes.Add(treeNode);
                    }
                }
    
                return nodes.ToJson();
            }
        </script
    It blows up with:
    System.Reflection.TargetInvocationException: Exception has  been thrown by the target of an invocation. --->  System.NullReferenceException: Object reference not set to an instance of an  object. at  ASP.examples_treepanel_loaders_ajax_method_loader_default_aspx.NodeLoad(String  nodeID) in  c:\Development\dotnet\Ext.Net\Ext.Net.Examples\Examples\TreePanel\Loaders\Ajax_Method_Loader\Default.aspx:line  37 --- End of inner exception stack trace --- at  System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments,  SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle  typeOwner) at System.RuntimeMethodHandle.InvokeMethodFast(Object target,  Object[] arguments, Signature sig, MethodAttributes methodAttributes,  RuntimeTypeHandle typeOwner) at  System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr,  Binder binder, Object[] parameters, CultureInfo culture, Boolean  skipVisibilityChecks) at System.Reflection.RuntimeMethodInfo.Invoke(Object obj,  BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo  culture) at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters)  at Ext.Net.DirectMethod.Invoke(Object target, HttpContext context,  ParameterCollection args) in  C:\Development\dotnet\Ext.Net\Ext.Net\Core\DirectMethod.cs:line 168 at  Ext.Net.DirectMethod.Invoke() in  C:\Development\dotnet\Ext.Net\Ext.Net\Core\DirectMethod.cs:line 111 at  Ext.Net.DirectRequestModule.ProcessRequest(HttpApplication app, HttpRequest  request) in  C:\Development\dotnet\Ext.Net\Ext.Net\Core\DirectRequestModule.cs:line  137
    So the workaround to register the icon doesn't work because there seems to be no resource manager on that execution thread.

    How else can we do it?

    Thanks
  3. #3
    I started to read the code and I think it is a problem with the way the famfam icons are handled.

    Because the images are serviced by the app (they are web resources), and they are serviced by urls such as this one

    http://localhost:3617/icons/applicat...et-png/ext.axd
    the used icons are cherry picked and added to a css file served dynamically.

    I would have separated the famafam set from the deployment and provide a css file with a class name for each icon.
  4. #4
    ok, I solved this problem by generating an icons.css file using this code:

    <%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>
    
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head id="Head1" runat="server">
       <title></title>
    
       <ext:ResourcePlaceHolder ID="ResourcePlaceHolder1" runat="server" />
       <script type="text/javascript" src="/scripts/jquery-1.5.1.min.js"></script>
    
    
    
    
    </head>
    <body>
      <ext:ResourceManager ID="ResourceManager1" runat="server" IDMode="Explicit" InitScriptMode="Linked" />
    
    
      <% foreach (Icon x in Enum.GetValues(typeof(Icon)))
         {%>
         <%= this.ResourceManager1.GetIconClass(x) %><br />
      <%
         }%>
     </body>
    </html>
    Then I referenced it in my page:

    <link rel="Stylesheet" type="text/css" href="../../Content/icons.css" />
    Now the icons show up.
  5. #5
    I have meet the same problem and use the code you hava show.But it doesn't work.
    When I run the applicatoin the page show the css 's code.What's the matter?
    Can you give me a demo?Many thanks~
  6. #6
    Quote Originally Posted by wflash View Post
    I have meet the same problem and use the code you hava show.But it doesn't work.
    When I run the applicatoin the page show the css 's code.What's the matter?
    Can you give me a demo?Many thanks~
    @wflash - It would be best to start a new thread. Please feel free to cross-link between topics if you feel they are related.
    Geoffrey McGill
    Founder

Similar Threads

  1. Replies: 5
    Last Post: Mar 23, 2011, 9:57 AM
  2. famfam icons
    By alemonnier in forum Licensing
    Replies: 3
    Last Post: Oct 08, 2010, 8:25 AM
  3. Custom icons
    By pil0t in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: May 17, 2010, 7:52 AM
  4. [CLOSED] TreePanel Example not working with custom Icons
    By randy85253 in forum 1.x Legacy Premium Help
    Replies: 3
    Last Post: Jun 16, 2009, 11:21 PM
  5. [CLOSED] Custom TreeNode Icons for a dynamic TreePanel
    By conman in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: Jan 15, 2009, 10:22 AM

Posting Permissions