LoadControl v calling constructor

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • a@a.co.uk

    LoadControl v calling constructor

    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

    #2
    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


    Comment

    • Jerry III

      #3
      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:eUuuNztnDH A.644@TK2MSFTNG P11.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]


      Comment

      Working...