473,395 Members | 1,763 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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
Nov 17 '05 #1
6 4353
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 http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 17 '05 #2
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 http://www.developersdex.com ***Don't just participate in USENET...get rewarded for it!
.

Nov 17 '05 #3
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 http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 17 '05 #4
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]- http://groups.yahoo.com/group/lusocoders/
[PontoNetPT]- http://www.programando.net/regras.aspx
jj***@acinet.pt.nospam - www.acinet.pt
================================================== =====
Nov 17 '05 #5
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 http://www.developersdex.com ***Don't just participate in USENET...get rewarded for it!
.

Nov 17 '05 #6
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 http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 17 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: DraguVaso | last post by:
Hi, In my application, on some given actions while debugging in Visual Studio, I suddenly get a "System.ComponentModel.Win32Exception was unhandled" Message="Error creating window handle."...
1
by: Don Hames | last post by:
I have created a window application in VS 2005 using C#. In the main form, I added a split container. I added controls to the left panel1 from the toolbox and they all work fine. I want to respond...
2
by: superseed | last post by:
Hi, I'm pretty new to C#, and I'm quite stuck on the following problem. I would like to add to my application a Windows.Form (singleton) on which I could display a message of one of the...
4
by: Rod Gill | last post by:
Hi, I have a form that when opened in the designer appears of the screen. The form selector can't be dragged (or resized) and if I scroll right and down to centralise it the form simply jumps...
3
by: EnglishMan69 | last post by:
Hello All, I am using VB2005 Beta 2 in VS 2005 and am running into a small problem. I need to be able to add a picture box to the main form from within a thread. The program goes to a web...
7
by: Varangian | last post by:
Hello is creating controls at runtime the same as designtime ? will a page be faster if controls are created at designtime rather than at runtime ? If so why ? thanks :)
1
by: John T Ingato | last post by:
With excel VBA, I can do : Dim ctrGo as commandbutton Set ctrGo = me.controls.add("Go") which would create a button on the form. Can I do with with Access? When I try it, first of all the...
5
by: Vibhesh | last post by:
I am facing problem with TimeSpan structure when DirectX is used. Following is the sample code that causes the problem: ...
5
by: Doc John | last post by:
I need to create several Windows Forms and I'm thinking of creating a base Form from which I can derive all Forms. Is it possible to include something in that Base Form so that all Forms I create...
8
by: BillE | last post by:
When I create a control dynamically and it grows according to the content, the control Height property still returns the original default control height instead of the height after expanding. ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.