Creating Form Controls at Run-Time

Ask a Question related to ASP.NET General, Design and Development.

  1. #1

    Default Creating Form Controls at Run-Time

    I would like to be able to create controls at run-time
    rather than at design time. Is there a function that I
    can override so that I can output the appropriate html
    code between when the <body> and </body> tags are outputed.

    I don't have to have web form controls but could just be
    plain html controls.

    Thanks
    Tarang Deshpande Guest

  2. Similar Questions and Discussions

    1. Control.Controls bug? Control's child controls missing at the run time.
      Hello, ..NET 1.1/VB.NET: I have a custom web control Public Class DatePicker Inherits Control Implements INamingContainer
    2. flash form: how to align form controls in table manner
      Lets say that we have three columns and two rows and each cell have an input. I can align the inputs vertically using html table. How do I do it the...
    3. need form controls list at design time
      Hello, I have created a server control and would like to have one of my properties have a drop down list with the controls on the current page as...
    4. Creating a emialed web form help needed big time
      Hi Folks, I'm new to flash 2 days but have managed to create a responce form for my small site at apple, the form is filled in then I want the...
    5. Creating form with tab controls
      Hi, I created about 5 forms (custumors, invoices, ....) I would like to use now the access2 tab control form to switch between these forms. I was...
  3. #2

    Default Re: Creating Form Controls at Run-Time

    You can create server controls or Html controls at the page_load event.
    you can also attach them to events :

    System.Web.UI.WebControls.ListBox oLst = new
    System.Web.UI.WebControls.ListBox();
    oLst.Enabled = true;
    oLst.EnableViewState = true;
    oLst.ID = "cboDevQueueList";
    oLst.AutoPostBack = true;
    oLst.Items.Add ("a");
    oLst.Items.Add ("b");
    oLst.Visible = true;
    oLst.SelectedIndexChanged += new System.EventHandler(this.SelItem);
    // ad the control inside the form
    ("WebForm6").Controls.Add(oLst);

    Natty Gur, CTO
    Dao2Com Ltd.
    28th Baruch Hirsch st. Bnei-Brak
    Israel , 51114

    Phone Numbers:
    Office: +972-(0)3-5786668
    Fax: +972-(0)3-5703475
    Mobile: +972-(0)58-888377

    Know the overall picture


    *** Sent via Developersdex [url]http://www.developersdex.com[/url] ***
    Don't just participate in USENET...get rewarded for it!
    Natty Gur Guest

  4. #3

    Default Re: Creating Form Controls at Run-Time

    How about if you want to create html controls rather than
    web controls what do you do? I tried using Response.Write
    during the Page_Load but that only puts the html code
    before everything else from the ASPX page.

    >-----Original Message-----
    >You can create server controls or Html controls at the
    page_load event.
    >you can also attach them to events :
    >
    >System.Web.UI.WebControls.ListBox oLst = new
    >System.Web.UI.WebControls.ListBox();
    >oLst.Enabled = true;
    >oLst.EnableViewState = true;
    >oLst.ID = "cboDevQueueList";
    >oLst.AutoPostBack = true;
    >oLst.Items.Add ("a");
    >oLst.Items.Add ("b");
    >oLst.Visible = true;
    >oLst.SelectedIndexChanged += new System.EventHandler
    (this.SelItem);
    >// ad the control inside the form
    >("WebForm6").Controls.Add(oLst);
    >
    >Natty Gur, CTO
    >Dao2Com Ltd.
    >28th Baruch Hirsch st. Bnei-Brak
    >Israel , 51114
    >
    >Phone Numbers:
    >Office: +972-(0)3-5786668
    >Fax: +972-(0)3-5703475
    >Mobile: +972-(0)58-888377
    >
    >Know the overall picture
    >
    >
    >*** Sent via Developersdex [url]http://www.developersdex.com[/url]
    ***
    >Don't just participate in USENET...get rewarded for it!
    >.
    >
    Tarang Deshpande Guest

  5. #4

    Default Re: Creating Form Controls at Run-Time

    The same way and location just use Html control classes:

    System.Web.UI.HtmlControls.HtmlInputText o = new
    System.Web.UI.HtmlControls.HtmlInputText ();
    o.Value = "natty";
    o.Visible = true;
    this.FindControl("WebForm6").Controls.Add(o);

    Natty Gur, CTO
    Dao2Com Ltd.
    28th Baruch Hirsch st. Bnei-Brak
    Israel , 51114

    Phone Numbers:
    Office: +972-(0)3-5786668
    Fax: +972-(0)3-5703475
    Mobile: +972-(0)58-888377

    Know the overall picture


    *** Sent via Developersdex [url]http://www.developersdex.com[/url] ***
    Don't just participate in USENET...get rewarded for it!
    Natty Gur Guest

  6. #5

    Default Re: Creating Form Controls at Run-Time

    Mind that if you are creating WebControls and you whant to preserve viewstate,
    the controls must be created on Page_Init.

    regards

    Joao Cardoso (MVP dotNET)
    ================================================== =====
    [LusoCoders]- [url]http://groups.yahoo.com/group/lusocoders/[/url]
    [PontoNetPT]- [url]http://www.programando.net/regras.aspx[/url]
    [email]jjscc@acinet.pt.nosp[/email]am - [url]www.acinet.pt[/url]
    ================================================== =====
    Joao S Cardoso [MVP] Guest

  7. #6

    Default Re: Creating Form Controls at Run-Time

    This doesn't quite work. I added label controls and if
    you look at the gnerated html code at the client the end
    result is rendered after the </HTML> tag and thus outside
    of the form. Also each label was between <span></span>
    tags.

    >-----Original Message-----
    >You can create server controls or Html controls at the
    page_load event.
    >you can also attach them to events :
    >
    >System.Web.UI.WebControls.ListBox oLst = new
    >System.Web.UI.WebControls.ListBox();
    >oLst.Enabled = true;
    >oLst.EnableViewState = true;
    >oLst.ID = "cboDevQueueList";
    >oLst.AutoPostBack = true;
    >oLst.Items.Add ("a");
    >oLst.Items.Add ("b");
    >oLst.Visible = true;
    >oLst.SelectedIndexChanged += new System.EventHandler
    (this.SelItem);
    >// ad the control inside the form
    >("WebForm6").Controls.Add(oLst);
    >
    >Natty Gur, CTO
    >Dao2Com Ltd.
    >28th Baruch Hirsch st. Bnei-Brak
    >Israel , 51114
    >
    >Phone Numbers:
    >Office: +972-(0)3-5786668
    >Fax: +972-(0)3-5703475
    >Mobile: +972-(0)58-888377
    >
    >Know the overall picture
    >
    >
    >*** Sent via Developersdex [url]http://www.developersdex.com[/url]
    ***
    >Don't just participate in USENET...get rewarded for it!
    >.
    >
    Tarang Deshpande Guest

  8. #7

    Default Re: Creating Form Controls at Run-Time

    Sorry, I have mistake at this line :>("WebForm6").Controls.Add(oLst);

    this.controls["YourFormName"].Controls.Add(oLst);

    you need to use the right Controls collection to add your control to.

    Natty Gur, CTO
    Dao2Com Ltd.
    28th Baruch Hirsch st. Bnei-Brak
    Israel , 51114

    Phone Numbers:
    Office: +972-(0)3-5786668
    Fax: +972-(0)3-5703475
    Mobile: +972-(0)58-888377

    Know the overall picture


    *** Sent via Developersdex [url]http://www.developersdex.com[/url] ***
    Don't just participate in USENET...get rewarded for it!
    Natty Gur Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139