[CLOSED] setting Ext.Net.Icon from config file in codebehind

  1. #1

    [CLOSED] setting Ext.Net.Icon from config file in codebehind

    Hello and thanks in advance for your help - hopefully this is fairly simple...

    In a codebehind, I am setting Icons for some menu items, but the icons that are used are stored in a config file as strings...how can i deserialize these strings so I can set the Icon property correctly - for example I want this:

    mc.Menu.Items.Add(new Ext.Net.MenuCommand() 
    {
        Icon = Ext.Net.Icon.EmailGo, 
        CommandName = "Email", 
        Text = "Send Email"
    });
    to work like this:

    for (int i = 0; i < configItems.length; i++)
    {
        mc.Menu.Items.Add(new Ext.Net.MenuCommand()
        {
            Icon = configItems.IconString,
            CommandName = configItems.CommandName,
            Text = configItems.Text
        });
    }
    Where configItems.IconString = "Ext.Net.EmailGo" (a string stored in a config file/database/etc...)
    Last edited by Daniil; Jan 18, 2012 at 5:39 AM. Reason: [CLOSED]
  2. #2

    another example of what i want to do

    Icon = (Ext.Net.Icon)Ext.Net.JSON.Deserialize("Ext.Net.Icon.EmailGo", Ext.Net.Icon);
    no luck there tho.......
    Last edited by Daniil; Jan 18, 2012 at 5:39 AM. Reason: Please use [CODE] tags
  3. #3
    Hi,

    Here you are.
    Icon icon = (Icon)Enum.Parse(typeof(Icon), "EmailGo");
    Please note an icon string must be without "Ext.Net" prefix.

    Here is a full example.

    Example
    <%@ Page Language="C#" %>
    
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    
    <script runat="server">
        protected void Page_Load(object sender, EventArgs e)
        {
            Icon icon = (Icon)Enum.Parse(typeof(Icon), "EmailGo");
            this.Form.Controls.Add(new Ext.Net.Button()
                {
                    Icon = icon
                });
        }
    </script>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>Ext.NET Example</title>
    </head>
    <body>
        <form runat="server">
            <ext:ResourceManager runat="server" />
        </form>
    </body>
    </html>
  4. #4
    In Ext.NET v2, we've added a new feature to the .IconCls property (all components) where you can now set an Icon Enum value as a string, by just prefixing the string Icon Enum name with a "#".

    Example

    // v1
    Icon = (Icon)Enum.Parse(typeof(Icon), "EmailGo");
    
    // v2
    IconCls = "#EmailGo"
    The string name MUST be exactly the same as the Enum value, and is case-sensitive.

    #EmailGo => works!
    #Emailgo => fails
    The following sample demonstrates a complete scenario.

    Example

    <%@ Page Language="C#" %> 
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
     
    <script runat="server">
        protected void Page_Load(object sender, EventArgs e)
        {
            this.Form.Controls.Add(new Ext.Net.Button()
            {
                IconCls = "#EmailGo"
            });
        }
    </script>
     
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>Ext.NET Example</title>
    </head>
    <body>
        <form runat="server">
            <ext:ResourceManager runat="server" />
        </form>
    </body>
    </html>
    This now avoids having to parse the string into a Enum and set the .Icon property, although that functionality is still supported. The new feature only applies to the .IconCls property.

    As mentioned above, this functionality is available in Ext.NET v2, including the current "Developer Preview 1" release.

    Hope this helps.

    Cheers!
    Last edited by Daniil; Jan 18, 2012 at 5:38 AM.
    Geoffrey McGill
    Founder
  5. #5

    YES!

    Thanks Daniil - and Geoffrey for the additional info re. v.2

    Exactly what i needed....thank you!!!!

Similar Threads

  1. Replies: 0
    Last Post: May 10, 2012, 1:33 AM
  2. [CLOSED] Problem config store and gridPanel in CodeBehind
    By supera in forum 2.x Legacy Premium Help
    Replies: 8
    Last Post: Feb 08, 2012, 9:48 AM
  3. Replies: 16
    Last Post: May 30, 2010, 1:13 AM
  4. Replies: 5
    Last Post: Jul 06, 2009, 3:02 PM
  5. [CLOSED] Error while setting theme in web.config
    By Jurke in forum 1.x Legacy Premium Help
    Replies: 5
    Last Post: Nov 25, 2008, 6:54 AM

Tags for this Thread

Posting Permissions