Question about loading usercontrols

  • Thread starter Thread starter B. Chernick
  • Start date Start date
B

B. Chernick

(I've been away from web app programming for a while. Most of my experience
has been in 1.1. Now I'm using vb/Dot Net 2.0)

Please explain a couple of things.

First, I have a simple-minded usercontrol defined. No real code so far.
Just a bunch of text boxes on a panel. I want to dynamically load one or
more instances of the usercontrol onto the screen.

Why is it that the command 'Me.Form.Controls.Add' will work with stock
controls (like a textbox) but apparently not with usercontrols? (After a
little bit of trial and error I found I could create usercontrols with the
'LoadControl' command. I think this is the first time I've heard of
'LoadControl'.)

2nd, in a basic web page, a control can be dynamically added with a call to
the default 'form1.controls.add'. My current test page has a master page and
I've found that 'form1' is not available. However 'Me.Form.Controls.Add()'
seems to work the same. Are there any 'gotchas' here that I should be aware
of?
 
B. Chernick said:
(I've been away from web app programming for a while. Most of my
experience
has been in 1.1. Now I'm using vb/Dot Net 2.0)

Please explain a couple of things.

First, I have a simple-minded usercontrol defined. No real code so far.
Just a bunch of text boxes on a panel. I want to dynamically load one or
more instances of the usercontrol onto the screen.

Why is it that the command 'Me.Form.Controls.Add' will work with stock
controls (like a textbox) but apparently not with usercontrols? (After a
little bit of trial and error I found I could create usercontrols with the
'LoadControl' command. I think this is the first time I've heard of
'LoadControl'.)

A textbox is fully compiled, so it does not require UI helpers to render the
tagged portion of the page. A user control is a mixture of code and tags. It
would not make sense spinning cycles on a compiled control to check for
tags, so you have different methods.
2nd, in a basic web page, a control can be dynamically added with a call
to
the default 'form1.controls.add'. My current test page has a master page
and
I've found that 'form1' is not available. However
'Me.Form.Controls.Add()'
seems to work the same. Are there any 'gotchas' here that I should be
aware
of?

It is the same. I have never experienced the problem you talk about, but I
am not sure I have ever coded it that way, so that is a moot point. I am not
sure why you are not seeing the form name, but Me.Form points to the same
location.

--
Gregory A. Beamer
MVP, MCP: +I, SE, SD, DBA

Subscribe to my blog
http://gregorybeamer.spaces.live.com/lists/feed.rss

or just read it:
http://gregorybeamer.spaces.live.com/

********************************************
| Think outside the box! |
********************************************
 
Back
Top