473,761 Members | 9,266 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 4365
You can create server controls or Html controls at the page_load event.
you can also attach them to events :

System.Web.UI.W ebControls.List Box oLst = new
System.Web.UI.W ebControls.List Box();
oLst.Enabled = true;
oLst.EnableView State = true;
oLst.ID = "cboDevQueueLis t";
oLst.AutoPostBa ck = true;
oLst.Items.Add ("a");
oLst.Items.Add ("b");
oLst.Visible = true;
oLst.SelectedIn dexChanged += new System.EventHan dler(this.SelIt em);
// ad the control inside the form
("WebForm6").Co ntrols.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.Lis tBox oLst = new
System.Web.UI. WebControls.Lis tBox();
oLst.Enabled = true;
oLst.EnableVie wState = true;
oLst.ID = "cboDevQueueLis t";
oLst.AutoPostB ack = true;
oLst.Items.A dd ("a");
oLst.Items.A dd ("b");
oLst.Visible = true;
oLst.SelectedI ndexChanged += new System.EventHan dler (this.SelItem);// ad the control inside the form
("WebForm6").C ontrols.Add(oLs t);

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.H tmlControls.Htm lInputText o = new
System.Web.UI.H tmlControls.Htm lInputText ();
o.Value = "natty";
o.Visible = true;
this.FindContro l("WebForm6").C ontrols.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.Lis tBox oLst = new
System.Web.UI. WebControls.Lis tBox();
oLst.Enabled = true;
oLst.EnableVie wState = true;
oLst.ID = "cboDevQueueLis t";
oLst.AutoPostB ack = true;
oLst.Items.A dd ("a");
oLst.Items.A dd ("b");
oLst.Visible = true;
oLst.SelectedI ndexChanged += new System.EventHan dler (this.SelItem);// ad the control inside the form
("WebForm6").C ontrols.Add(oLs t);

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(oL st);

this.controls["YourFormNa me"].Controls.Add(o Lst);

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
3250
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." exception. The problem is that this exception isn't raised somewhere in a method, so it just shows up, and it causes the application to shut down. Is there anyway how to catch this kinds of exceptions? Can I put somewhere a
1
3545
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 to events from the controls in the left panel1 and dynamically instantiate user controls that I have created in the project. If I drag the user control from the toolbox into the right panel2, it works fine. I copied they generated code and removed...
2
2657
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 following type : Exception, Error, Warning, Infos (with differents colors, etc). I would like to use it like the Console.WriteLine("My Message"); on everywhere in my application.
4
3159
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 further away, completely leaving the selector box area. Any ideas? VS 2003 and VB.Net This is a simple application at the moment but the form is inherited from a
3
3695
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 site, performs a search based on POST variables, retrieves the code, parses the information (including a url for a thumbnail image) and displays the results. I am using threads, since the program will appear to freeze while
7
2226
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
7626
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 is not a method "Add" available. when I run it, it fails at this line.
5
2007
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: *************************************************************************************************************** { ........................... PrintTimeSpanProblem(); device = new Device(0, DeviceType.Hardware, this, CreateFlags.SoftwareVertexProcessing, presentParams); PrintTimeSpanProblem();
5
1827
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 will use some specific controls with some specific properties? For example, if I add to the Base Form a button with a black background ans Arial Font, will all the Forms be required to use this same Button? Thanks.
8
2816
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. How can I get the height of the control (in code) after it grows? I am building a windows form dynamically, creating controls and placing them on the form. There can be dozens of controls of all types on the form. This is for dynamic...
0
10115
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9957
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9905
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9775
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8780
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7332
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6609
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5373
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2752
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.