[CLOSED] How to add 2 userControl inherited by Ext.Net.Container?

  1. #1

    [CLOSED] How to add 2 userControl inherited by Ext.Net.Container?

    Hi,

    I've got written a control inherited from Ext.Net.Container. Now when I add 2 same control with different Ids (contains 1 button with same Id) it's make exception
    A Control with an ID of "btnSampleButton" has already been initialized. Please ensure that all Controls have a unique id.
    Here's example I'm using v1.5 Ext.Net
    page code
    <%@ Page Language="C#" %>
    
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    
    <script runat="server">
        protected void Page_Load(object sender, EventArgs e)
            {
                SampleControl sampleControl1 = new SampleControl();
                sampleControl1.ID = "sample1";
                SampleControl sampleControl2 = new SampleControl();
                sampleControl2.ID = "sample2";
                pnlExt.Items.Add(sampleControl1);
                pnlExt.Items.Add(sampleControl2);
            }
    </script>
    
    <!DOCTYPE html>
    
    <html>
    <head runat="server">
        <title>CardLayout - Ext.NET Examples</title>
    </head>
    <body>
        <form runat="server">
            <ext:ResourceManager ID="ResourceManager1" runat="server" />
            <ext:Viewport runat="server">
                <Items>
                    <ext:Panel runat="server" ID="pnlExt"></ext:Panel>
                </Items>
            </ext:Viewport>
        </form>
    </body>
    </html>
    control code
    using Ext.Net;
    
    namespace Sample
    {
        public class SampleControl : Ext.Net.Container
        {
            private Ext.Net.Button btnSample;
    
            public SampleControl()
            {
                btnSample = new Ext.Net.Button{ID="btnSampleButton", Text = "Sample Button " + this.ID};
                this.Items.Add(btnSample);
            }
        }
    }
    How can I make it work? Please let me know if this is already resolved in Ext.Net 2.0v. I'll reconsider to update newest version if that kind of errors are resolved.
    Last edited by Daniil; Sep 21, 2012 at 11:05 AM. Reason: [CLOSED]
  2. #2
    Hi,

    Good choice to implement custom controls!

    1. You can change the ID of the Button:
    ID = this.ID + "_btnSampleButton"
    2. You can use ItemID if you don't need to access this Button on server side, but need on client only.
    http://docs.sencha.com/ext-js/3-4/#!...ent-cfg-itemId
  3. #3
    Quote Originally Posted by Daniil View Post
    Hi,

    Good choice to implement custom controls!

    1. You can change the ID of the Button:
    ID = this.ID + "_btnSampleButton"
    2. You can use ItemID if you don't need to access this Button on server side, but need on client only.
    http://docs.sencha.com/ext-js/3-4/#!...ent-cfg-itemId
    I've tryed that already I mean (
    ID = this.ID + "_btnSampleButton"
    ); but it doesn't work for me;/
    any other ideas?;>

    Thanks
  4. #4
    I tried your code, it works well for me with
    ID = this.ID + "_btnSampleButton"
    but it doesn't work for me;/
    Any details, please?
  5. #5
    Quote Originally Posted by Daniil View Post
    I tried your code, it works well for me with
    ID = this.ID + "_btnSampleButton"


    Any details, please?
    sadly this.ID is null in constructor and on OnInit event. I was able to create and make it work OnLoad event which is really wird but work for now.
  6. #6
    Well, because the ID is applied after creating the Button.

    SampleControl sampleControl1 = new SampleControl();
    sampleControl1.ID = "sample1";
    After execution of the first line the Button is already created.

    So, yes, it would be better to create the Buttons within an OnInit handler.
  7. #7
    Quote Originally Posted by Daniil View Post
    Well, because the ID is applied after creating the Button.

    SampleControl sampleControl1 = new SampleControl();
    sampleControl1.ID = "sample1";
    After execution of the first line the Button is already created.

    So, yes, it would be better to create the Buttons within an OnInit handler.
    event when i make override which got parameter:
    public SampleControl(string id)
    {
         this.ID = id;
    }
    and ID still null then.

    I wonder is this normal behaviour or It's should work different way which will mean I'm doing something wrong?
  8. #8
    Could you provide a full sample?
  9. #9
    Quote Originally Posted by Daniil View Post
    Could you provide a full sample?
    I figured it out ID is null on Constructor. but
    OnInit
    event it has value.

    Thread can be closed thanks :)

Similar Threads

  1. Replies: 1
    Last Post: May 29, 2013, 6:00 PM
  2. Replies: 1
    Last Post: Jan 19, 2012, 4:20 PM
  3. Replies: 0
    Last Post: Aug 03, 2011, 10:27 PM
  4. [CLOSED] Register javascript resource to inherited control
    By Pablo_Azevedo in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: Nov 11, 2010, 8:24 PM
  5. Replies: 3
    Last Post: Oct 07, 2009, 6:32 PM

Tags for this Thread

Posting Permissions