Question about loading usercontrols

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?
 
C

Cowboy \(Gregory A. Beamer\)

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,754
Messages
2,569,520
Members
44,996
Latest member
rainocode

Latest Threads

Top