Error When adding controls to form panel dynamically

  1. #1

    Error When adding controls to form panel dynamically

    Hi, I have a form panel and when I add controls dynamically to it I get following JavaScript error.

    Uncaught TypeError: Cannot read property 'removeCls' of null
    at ctor.toggleInvalidCls (ext.axd?v=4.7.1:20)
    at ctor.renderActiveError (ext.axd?v=4.7.1:20)
    at ctor.renderActiveError (ext.axd?v=4.7.1:20)
    at ctor.onRender (ext.axd?v=4.7.1:20)
    at ctor.callParent (ext.axd?v=4.7.1:20)
    at ctor.onRender (ext.axd?v=4.7.1:581)
    at ctor.callParent (ext.axd?v=4.7.1:20)
    at ctor.onRender (ext.axd?v=4.7.1:656)
    at ctor.onRender (ext.axd?v=4.7.1:20)
    at ctor.finishRender (ext.axd?v=4.7.1:20)


    My Code
    .ascx File

    <ext:FormPanel
    ID="frmPanelGeneral"
    runat="server"
    BodyPaddingSummary="5 5 0"
    Width="650"
    Frame="true"
    AutoScroll="true"
    ButtonAlign="Center">
    <FieldDefaults LabelWidth="135" InputWidth="325">
    </FieldDefaults>

    <Items>
    </Items>
    <Buttons>
    <ext:Button runat="server" Text="Save">
    <DirectEvents>
    <Click OnEvent="SavePolicyInfo"></Click>
    </DirectEvents>
    </ext:Button>
    <ext:Button runat="server" ID="Button1" Text="Cancel">
    <Listeners>
    <Click Handler="fnUploadWindowClose();" />
    </Listeners>
    </ext:Button>
    </Buttons>
    </ext:FormPanel>


    .ascx.cs file:


    textField = new Ext.Net.TextField();
    textField.ID = "txt" + key;
    textField.FieldLabel = key;
    textField.Name = key;
    frmPanelGeneral.Items.Add(textField);
    textField.Render();
  2. #2
    Hello, @hirakpatel81!

    From the code you posted, I have absolutely no clue on what could be going on. But there's an online example that seems to be doing exactly what you need. Not sure how "dynamically" the controls are added to your page though.

    - Layout - FormLayout - From UserControls

    Maybe if you provided a runnable sample based on the online one, we could reproduce what you are facing and be able to give proper advice.

    I would also like the opportunity to ask you to edit your original post wrapping code blocks around blocks. It gets much better to read the code in the proper blocks.

    You should also take your time to review our forums guidelines, as they not only help us help you, but also helps you find out the problem easier than otherwise.
    - Tips for creating simplified code samples
    - More Information Required
    - Forum Guidelines

    Hope this helps!
    Fabrício Murta
    Developer & Support Expert
  3. #3

    Found Issue

    Hi I found the issue.

    textField = new Ext.Net.TextField();
    textField.ID = "txt" + key;
    textField.FieldLabel = key;
    textField.Name = key;
    frmPanelGeneral.Items.Add(textField);
    textField.Render();

    When I add the text field dynamically, I am creating the ID by concatenating string. I found that when I do "txt"+key, key has space inside it.

    It was working fine with space in ID when I was using version 2. But I upgraded to version 4.7.1 and it did not allowed me to do that.

    Thanks
    Hirak

Similar Threads

  1. [CLOSED] Adding code behind controls to form
    By tMp in forum 2.x Premium Help
    Replies: 7
    Last Post: Jan 08, 2014, 12:15 PM
  2. Dynamically adding Controls to WebUserControl
    By bright in forum 1.x Help
    Replies: 8
    Last Post: Apr 27, 2012, 7:34 PM
  3. [CLOSED] Adding Elements to a form dynamically
    By ljcorreia in forum 1.x Premium Help
    Replies: 2
    Last Post: Jun 21, 2011, 5:33 PM
  4. Dynamically adding form fields
    By sz_146 in forum 1.x Help
    Replies: 4
    Last Post: Nov 11, 2008, 12:10 PM
  5. [CLOSED] Dynamically adding controls to a tav
    By riccardosarti in forum 1.x Help
    Replies: 3
    Last Post: Sep 24, 2008, 10:49 AM

Posting Permissions