LoadControl v calling constructor

  • Thread starter Thread starter a
  • Start date Start date
A

a

Hi
Extremely easy question for someone who knows the answer I'm sure
:-) (aren't they all)

What exactly does LoadControl do? Whats the difference between calling
this and just constructing a user control?

Thanks

anon'ish
 
You need to understand the difference between Web Custom Controls and Web
User Controls.

Web Custom Controls, like the WebControls (DataGrid, Button, ...) are
classes. To create them you just call their constructor:
Dim b as Button = new Button()

Web User Controls are defined by an ASCX page (containing HTML) and a class.
The class is just the codebehind for the control, so if you call its
constructor you don't create the control. That's where the LoadControl
method is needed: you pass it the name of the ASCX page, and it loads both
this page and the CodeBehind class.
 
When you create an ascx file you can specify the class name of the auto
generated class. The question is what is the difference between calling
LoadControl and calling a constructor of the generated class?

Jerry
 
Back
Top