Connecting Tech Pros Worldwide Help | Site Map

LoadControl v calling constructor

a@a.co.uk
Guest
 
Posts: n/a
#1: Nov 17 '05
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
AW
Guest
 
Posts: n/a
#2: Nov 17 '05

re: LoadControl v calling constructor


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.
--
To reply, remove a "l" before the @ sign.

AW - MCT, MCSD.Net, MCAD.Net


Jerry III
Guest
 
Posts: n/a
#3: Nov 17 '05

re: LoadControl v calling constructor


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

"AW" <aweill@fr.xrt.com> wrote in message
news:eUuuNztnDHA.644@TK2MSFTNGP11.phx.gbl...[color=blue]
> 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[/color]
class.[color=blue]
> 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.
> --
> To reply, remove a "l" before the @ sign.
>
> AW - MCT, MCSD.Net, MCAD.Net
>
>[/color]


Closed Thread