Professional Web Applications Themes

Creating Form Controls at Run-Time - ASP.NET General

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...

  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. #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

  3. #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

  4. #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

  5. #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./group/lusocoders/[/url]
    [PontoNetPT]- [url]http://www.programando.net/regras.aspx[/url]
    [email]jjsccacinet.pt.nosp[/email]am - [url]www.acinet.pt[/url]
    ================================================== =====
    Joao S Cardoso [MVP] Guest

  6. #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

  7. #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

Similar Threads

  1. Control.Controls bug? Control's child controls missing at the run time.
    By sinelnikov.andrei@gmail.com in forum ASP.NET Building Controls
    Replies: 1
    Last Post: December 8th, 06:47 AM
  2. flash form: how to align form controls in table manner
    By jshaffner in forum Macromedia ColdFusion
    Replies: 3
    Last Post: February 18th, 07:35 PM
  3. need form controls list at design time
    By Kent in forum ASP.NET Building Controls
    Replies: 0
    Last Post: August 24th, 12:35 AM
  4. Creating a emialed web form help needed big time
    By martincornfoot@telefonica.net in forum Macromedia Flash
    Replies: 0
    Last Post: September 26th, 08:20 AM
  5. Creating form with tab controls
    By qpurser in forum Microsoft Access
    Replies: 4
    Last Post: July 12th, 07:19 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not 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