General discussion


Add controls to a form at runtime

By MaryWeilage Editor ·
This week's Visual Basic e-newsletter discusses adding controls to a form at runtime. Is this tip useful to you? Do you plan to add controls to a form at runtime? What VB tricks do you use all the time that you'd like to share with your peers? Please let us know.

If you aren't subscribed to our free Visual Basic e-newsletter, click the following link to automatically sign up:

This conversation is currently closed to new comments.

1 total post (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Comments

Collapse -

Followup with corresponding ASP.NET tip?

by ChuckR314159 In reply to Add controls to a form at ...

It was interesting that I got this tip while I was trying to deal with adding runtime controls in ASP.NET for the first stime. There are what I think are some very counter-intuitive things about adding run-time controls in ASP.NET/VB.NET that I think would be great to cover in a followup tip. Things that I've learned such as...

(1) Adding and using controls in control collections.

(2) The fact that in ASP.NET, ViewState seems to remember everything about a runtime control except for the fact that it exists. So you have to re-add the control to the form upon Post-back in order to access the properties you set when you added it or to respond to its events. (That's the counter-intuitive part)

(3) Then even if you deal with (2), you need to know that you must re-add the runtime controls in Page_Init rather than Page_Load, otherwise ViewState remembers everything about the control other than its value.

There are probably other things I don't yet understand about adding run-time controls in ASP.NET/VB.NET, so I think it would make for a useful followup article.


Back to Web Development Forum
1 total post (Page 1 of 1)  

Related Discussions

Related Forums