Working with Id on server-side

  1. #1

    Working with Id on server-side

    Hello.

    I have some problems with understanding, how Ext.Net generate and use Id. In my project, I have the DirectEvent, generating components dynamicly and sending their to client. For example, create tab for TabPanel:

    protected void AddNewTab(object sender, DirectEventArgs e)
    {
         var newTab = new Panel
         {
              Title = "New tab is here"
         };
    
         newTab.AddTo(this.TabPanel1);
    }
    It work well, but when I try to use Id in this server code, It doesn't work. For example, I want to switch TabPanel on new tab like

    this.TabPanel1.SetActiveTab(newTab);
    In server response I see someone like

    App.TabPanel1.setActiveTab(\"idae52d82ffdd6c7f1\");
    So Id has generated, but client side doesn't see it.
    How I can realise this functionality without generating Id manually?
  2. #2
    Hi @Sion,

    Welcome to the Ext.NET forums!

    A Control's ID is generated, but an implicit ID is not rendered to client.

    I can suggest to set it explicitly using a BaseControl's GenerateID method.
    var newTab = new Ext.Net.Panel
    {
        ID = BaseControl.GenerateID(),
        Title = "New tab is here"
    };
    Here is a full example.

    Example
    <%@ Page Language="C#" %>
    
    <script runat="server">
        protected void AddNewTab(object sender, DirectEventArgs e)
        {
            var newTab = new Ext.Net.Panel
            {
                ID = BaseControl.GenerateID(),
                Title = "New tab is here"
            };
    
            newTab.AddTo(this.TabPanel1);
            this.TabPanel1.SetActiveTab(newTab);
        }
    </script>
    
    <!DOCTYPE html>
    <html>
    <head runat="server">
        <title>Ext.NET v3 Example</title>
    </head>
    <body>
        <form runat="server">
            <ext:ResourceManager runat="server" />
    
            <ext:Button runat="server" Text="Add a Tab" OnDirectClick="AddNewTab" />
    
            <ext:TabPanel ID="TabPanel1" runat="server" />
        </form>
    </body>
    </html>
  3. #3
    Thank you, Daniil. Now It's work!

    Next question is more decoration, than necessity, but how I can get more friendly Id like "panel-35" or "button-43", which, as I saw in my work project, was generated for children elements of the panel?
  4. #4
    "panel-35" or "button-43"
    Those IDs are generated on client side if a component doesn't have an explicit id config. It is being generated client side in the only page context. In such case it is easier to make it more friendly-looking and still guarantee it is unique on the page.

    As for BaseControl.GenerateID() it has to guarantee uniqueness across an entire application. Also it is just a static method which doesn't have any information it generates an ID for a Panel or a Button.

    It looks like there is no a built-in method to generate a server side ID that you would like to have. To achieve it please replace BaseControl.GenerateID() with your own method.
  5. #5
    Thank you for reply. Thread can be closed.

Similar Threads

  1. Replies: 2
    Last Post: Sep 12, 2015, 11:04 AM
  2. Replies: 3
    Last Post: Dec 26, 2011, 1:32 PM
  3. Replies: 4
    Last Post: Mar 19, 2010, 11:35 AM

Tags for this Thread

Posting Permissions