[CLOSED] Create controls dynamicly

  1. #1

    [CLOSED] Create controls dynamicly

    The following code does not work in Coolite v0.8, which can work well in v0.7

    Error message of firebug : invalid label

    base.OnLoad(e);
      int index = 1;
      foreach(var item in Model.Questions)
      {
          // Question Content
          Coolite.Ext.Web.Label questionLable = new Coolite.Ext.Web.Label();
          questionLable.StyleSpec = "margin-top:20px";
          questionLable.Text = "{0}. {1}".FormatWith(index,item.QuestionText);
          TakeQuizFormLayout.Items.Add(questionLable);
          
          //
          Coolite.Ext.Web.Panel questionPanel = new Coolite.Ext.Web.Panel();
          questionPanel.BodyBorder = false;
    
          ColumnLayout columnLayout = new ColumnLayout();
          
          // Radio Group section
          LayoutColumn layoutColumn1 = new LayoutColumn();
          layoutColumn1.ColumnWidth = 0.3M;
    
          Coolite.Ext.Web.Panel radioGroupPanel = new Coolite.Ext.Web.Panel();
          radioGroupPanel.BodyBorder = false;
    
          // True Radio
          Radio trueRadio = new Radio();
          trueRadio.ID = "TrueRadio" + index;
          trueRadio.BoxLabel = "True";
    
          // False Radio
          Radio falseRadio = new Radio();
          falseRadio.ID = "FalseRadio" + index;
          falseRadio.BoxLabel = "False";
    
          RadioGroup radioGroup = new RadioGroup();
          radioGroup.Width = 100;
          radioGroup.ColumnsNumber = 1;
          radioGroup.FieldLabel = "RadioGroup";
          radioGroup.StyleSpec = "margin-left:30px;";
          radioGroup.Items.Add(trueRadio);
          radioGroup.Items.Add(falseRadio);
    
          layoutColumn1.Items.Add(radioGroup);
          columnLayout.Columns.Add(layoutColumn1);
    
          // General Lable section
          LayoutColumn layoutColumn2 = new LayoutColumn();
          layoutColumn2.ColumnWidth = 0.7M;
    
          Coolite.Ext.Web.Label generalLabel = new Coolite.Ext.Web.Label();
          generalLabel.ID = "GeneralLable" + index;
          generalLabel.StyleSpec = "top:20px;position:relative;";
          generalLabel.Html = "";
          layoutColumn2.Items.Add(generalLabel);
    
          columnLayout.Columns.Add(layoutColumn2);
    
          questionPanel.Items.Add(columnLayout);
    
          TakeQuizFormLayout.Items.Add(questionPanel);
          
          index++;
      }
    }
  2. #2

    RE: [CLOSED] Create controls dynamicly

    Can you post a simple .aspx code sample demonstrating how to reproduce this issue. See

    http://forums.ext.net/showthread.php...ing-New-Topics

    I get an exception when I attempt to run your code.
    Last edited by geoffrey.mcgill; Feb 19, 2011 at 5:42 AM.
    Geoffrey McGill
    Founder
  3. #3

    RE: [CLOSED] Create controls dynamicly

    Dear geoffery,
    Please review the following code.
    Thanks for your help!
        <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebApplication1._Default" %>
    
    <%@ Register Assembly="Coolite.Ext.Web" Namespace="Coolite.Ext.Web" TagPrefix="ext" %>
    
    <!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></title>
    </head>
    <body>
        <ext:ScriptManager ID="ScriptManager1" runat="server">
        </ext:ScriptManager>
     <ext:Panel ID="TakeQuizPanel" runat="server" BodyBorder="false" Cls="contentContainer">
                <Body>
                    <ext:FormLayout ID="TakeQuizFormLayout" runat="server" LabelAlign="Top">
                    </ext:FormLayout>
                </Body>
            </ext:Panel>
    </body>
    </html>
    <script runat="server">
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            // Question Content
            Coolite.Ext.Web.Label questionLable = new Coolite.Ext.Web.Label();
            questionLable.StyleSpec = "margin-top:20px";
            questionLable.Text = "test1";
            TakeQuizFormLayout.Items.Add(questionLable);
    
            //
            Coolite.Ext.Web.Panel questionPanel = new Coolite.Ext.Web.Panel();
            questionPanel.BodyBorder = false;
    
            ColumnLayout columnLayout = new ColumnLayout();
    
            // Radio Group section
            LayoutColumn layoutColumn1 = new LayoutColumn();
            layoutColumn1.ColumnWidth = 0.3M;
    
            Coolite.Ext.Web.Panel radioGroupPanel = new Coolite.Ext.Web.Panel();
            radioGroupPanel.BodyBorder = false;
    
            // True Radio
            Radio trueRadio = new Radio();
            trueRadio.ID = "TrueRadio";
            trueRadio.BoxLabel = "True";
    
            // False Radio
            Radio falseRadio = new Radio();
            falseRadio.ID = "FalseRadio";
            falseRadio.BoxLabel = "False";
    
            RadioGroup radioGroup = new RadioGroup();
            radioGroup.Width = 100;
            radioGroup.ColumnsNumber = 1;
            radioGroup.FieldLabel = "RadioGroup";
            radioGroup.StyleSpec = "margin-left:30px;";
            radioGroup.Items.Add(trueRadio);
            radioGroup.Items.Add(falseRadio);
    
            layoutColumn1.Items.Add(radioGroup);
            columnLayout.Columns.Add(layoutColumn1);
    
            // General Lable section
            LayoutColumn layoutColumn2 = new LayoutColumn();
            layoutColumn2.ColumnWidth = 0.7M;
    
            Coolite.Ext.Web.Label generalLabel = new Coolite.Ext.Web.Label();
            generalLabel.ID = "GeneralLable";
            generalLabel.StyleSpec = "top:20px;position:relative;";
            generalLabel.Html = "testsssss";
            layoutColumn2.Items.Add(generalLabel);
    
            columnLayout.Columns.Add(layoutColumn2);
    
            questionPanel.Items.Add(columnLayout);
    
            TakeQuizFormLayout.Items.Add(questionPanel); 
        }
    </script>
  4. #4

    RE: [CLOSED] Create controls dynamicly

    Hi Ningdev,

    When using the AnchorLayout, the controls should be added to the .Anchors Collection, instead of the .Items Collection.

    Example

    Anchor anchor = new Anchor();
    anchor.Items.Add(questionLable);
    TakeQuizFormLayout.Anchors.Add(anchor);
    I also added a couple shortcut helpers to simplify adding new Components to the AnchorLayout. The above code can be reduced to the following.

    Example

    TakeQuizFormLayout.Anchors.Add(questionPanel);
    Hope this helps.

    Geoffrey McGill
    Founder
  5. #5

    RE: [CLOSED] Create controls dynamicly

    Thanks for your help! It does work now!

Similar Threads

  1. [CLOSED] Create Controls at Runtime
    By rnachman in forum 1.x Legacy Premium Help
    Replies: 3
    Last Post: Feb 24, 2011, 6:32 PM
  2. [CLOSED] [1.0] Issue with dynamicly created user controls (viewstate)
    By klaus.schwarz in forum 1.x Legacy Premium Help
    Replies: 7
    Last Post: Nov 11, 2010, 12:12 PM
  3. Replies: 14
    Last Post: Nov 03, 2010, 3:40 PM
  4. [CLOSED] [1.0] Loading controls dynamicly ?
    By klavsm in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: Dec 14, 2009, 6:29 AM

Posting Permissions