473,322 Members | 1,690 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,322 software developers and data experts.

Dynamically add controls to a web form

Can one add a serverside control to a webform
dynamically? I used in the Page_load event of the form
the following code:

Dim txt as new System.Web.UI.Webcontrols.Textbox()
Controls.add(txt)

The code fails. Does this mean you just cannot in
Webforms where you CAN in Windows Forms?

Thanks
Nov 17 '05 #1
5 1797
Angel,

You can certainly add controls dynamically.

What is the error message?

Sincerely,

--
S. Justin Gengo, MCP
Web Developer

Free code library at:
www.aboutfortunate.com

"Out of chaos comes order."
Nietzche
"Angel" <as****@hotmail.com> wrote in message
news:05****************************@phx.gbl...
Can one add a serverside control to a webform
dynamically? I used in the Page_load event of the form
the following code:

Dim txt as new System.Web.UI.Webcontrols.Textbox()
Controls.add(txt)

The code fails. Does this mean you just cannot in
Webforms where you CAN in Windows Forms?

Thanks

Nov 17 '05 #2
Perhaps, it will be useful if you can include your code.

Thanks
"S. Justin Gengo" <sj*****@aboutfortunate.com> wrote in message
news:#4*************@TK2MSFTNGP11.phx.gbl...
Angel,

You can certainly add controls dynamically.

What is the error message?

Sincerely,

--
S. Justin Gengo, MCP
Web Developer

Free code library at:
www.aboutfortunate.com

"Out of chaos comes order."
Nietzche
"Angel" <as****@hotmail.com> wrote in message
news:05****************************@phx.gbl...
Can one add a serverside control to a webform
dynamically? I used in the Page_load event of the form
the following code:

Dim txt as new System.Web.UI.Webcontrols.Textbox()
Controls.add(txt)

The code fails. Does this mean you just cannot in
Webforms where you CAN in Windows Forms?

Thanks


Nov 17 '05 #3
SSW
U need to have a Place holder or Panel to add control.

Dim txt as new System.Web.UI.Webcontrols.Textbox()
PHtxt.Controls.add(txt)// where PHtxt is PlaceHolder web controls

Thanks,

sswalia
MCSD, MCAD, OCA.

"Angel" <as****@hotmail.com> wrote in message
news:05****************************@phx.gbl...
Can one add a serverside control to a webform
dynamically? I used in the Page_load event of the form
the following code:

Dim txt as new System.Web.UI.Webcontrols.Textbox()
Controls.add(txt)

The code fails. Does this mean you just cannot in
Webforms where you CAN in Windows Forms?

Thanks

Nov 17 '05 #4

"SSW" <fr************@hotmail.com> wrote in message
news:eH**************@tk2msftngp13.phx.gbl...
U need to have a Place holder or Panel to add control.

Dim txt as new System.Web.UI.Webcontrols.Textbox()
PHtxt.Controls.add(txt)// where PHtxt is PlaceHolder web controls


No, you shouldn't need a placeholder or panel. I add controls to pages all
the time without placeholders.

Some pages don't have a Controls collection at all. Maybe that's the
problem. If a page uses <% ... %> code blocks mixed with HTML (the old ASP
style) then the whole page ends up as a bunch of Response.Write statements
instead of having a Controls collection with LiteralControl objects
interleaved with other ASP.NET controls.
Nov 17 '05 #5
SSW
So it's alway safe to use placeholder/Panel to dunamically added controls.
Loaction is know at desing time.

I prefer using panel/Pace holder and it should work for all the case.

Thanks,

sswalia
MCSD, MCAD, OCA
Nov 17 '05 #6

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

Similar topics

3
by: Kiyomi | last post by:
Hello, I create a Table1 dynamically at run time, and at the same time, I would like to create LinkButton controls, also dynamically, and insert them into each line in my Table1. I would...
7
by: Tim T | last post by:
Hi, I have the need to use dynamically loaded user controls in a webform page. I have the controls loading dynamically, and that part works fine. this is the code used in a webform to dynamically...
8
by: Donald Xie | last post by:
Hi, I noticed an interesting effect when working with controls that are dynamically loaded. For instance, on a web form with a PlaceHolder control named ImageHolder, I dynamically add an image...
4
by: Sandeep | last post by:
Hi I am doing one thing in my website ,actually i want to add controls dynamically to a web form and want to access the elements but when i postback the form,and access that control, it gives...
1
by: Kamal Jeet Singh | last post by:
Hi Friends !! I am have facing problem in controlling the dynamically created controls on web page. The problem Scenario is Scenario:- My requirement is to load the web user controls on the...
1
by: Kamal Jeet Singh | last post by:
Hi Friends !! I am facing problem in controlling the dynamically created controls on web page. The problem Scenario is Scenario:- My requirement is to load the web user controls on the web...
2
by: Chad | last post by:
I have a problem that I am desperate to understand. It involves dynamically adding controls to a Table control that is built as a result of performing a database query. I am not looking to...
6
by: Steve Booth | last post by:
I have a web form with a button and a placeholder, the button adds a user control to the placeholder (and removes any existing controls). The user control contains a single button. I have done all...
5
by: Amoril | last post by:
I've read quite a few different message on various boards and for some reason I'm still having trouble wrapping my head around this viewstate maintenance and trying to get these dynamically created...
1
by: semomaniz | last post by:
I have a form where i have created the form dynamically. First i manually added a panel control to the web page. Then i added another panel dynamically and inside this panel i created tables. I have...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.