Dynamically added user control throws object not set

Discussion in 'ASP .Net' started by andyrich_1@hotmail.com, Jan 3, 2006.

  1. Guest

    HI,

    I'm adding a usercontrol to a webform in the following way


    Dim ctlRate As New ctlRatesTable
    ctlRate.SomeMethod()
    Me.Page.Controls.Add(ctlRate)

    Where sub routine "SomeMethod" attempts to set the text property of a
    lable webcontrol. The problem is that the lable hasn't been created.
    I've tried calling EnsureChildControls() before using the lable control
    but this hasn't helped.

    Any ideas what I'm doing wrong?

    Thanks,
    Andy
     
    , Jan 3, 2006
    #1
    1. Advertising

  2. Teemu Keiski Guest

    Try putting it also like this:

    ***
    Dim ctlRate As New ctlRatesTable

    ' FOLLOWING TWO LINES IN DIFFERENT ORDER THAN ORIGINALLY
    Me.Page.Controls.Add(ctlRate)
    ctlRate.SomeMethod()

    And yes, inside ctlRatesTable, before accessing child controls make sure
    EnsureChildControls is called (and child controls instantiated in
    CreateChildControls method)


    --
    Teemu Keiski
    ASP.NET MVP, AspInsider
    Finland, EU
    http://blogs.aspadvice.com/joteke


    <> wrote in message
    news:...
    > HI,
    >
    > I'm adding a usercontrol to a webform in the following way
    >
    >
    > > > >

    > Where sub routine "SomeMethod" attempts to set the text property of a
    > lable webcontrol. The problem is that the lable hasn't been created.
    > I've tried calling EnsureChildControls() before using the lable control
    > but this hasn't helped.
    >
    > Any ideas what I'm doing wrong?
    >
    > Thanks,
    > Andy
    >
     
    Teemu Keiski, Jan 3, 2006
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Bennett Haselton
    Replies:
    1
    Views:
    543
    John M Deal
    Nov 8, 2004
  2. Jon B
    Replies:
    5
    Views:
    5,259
  3. =?Utf-8?B?U2FtdWVs?=
    Replies:
    7
    Views:
    1,073
    Scott Allen
    Aug 10, 2005
  4. Phoenix
    Replies:
    2
    Views:
    257
    Teemu Keiski
    Jun 6, 2005
  5. Cathy

    Dynamically Added User Control not accessible!

    Cathy, Dec 16, 2003, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    135
    Cathy
    Dec 16, 2003
Loading...

Share This Page