Controls Not Instantiated on UserControl

Discussion in 'ASP .Net Web Controls' started by Eric Robishaw, Dec 18, 2003.

  1. What's the deal?

    If I place a control, a standard Web control (like a panel, or server-side
    Table), onto a Web User Control I've created, I can't access the control
    from the Code-Behind code.

    In the Page_Load event of the Web User Control, if I say:

    PlaceHolder1.Controls.Add (new LiteralControl ("<img src='bla.gif'>"));

    I get an error: Object null. And sure enough, PlaceHolder1 has no value
    set.

    If I do a "This.Controls.Count" I get a big fat zero.

    What's the deal.

    Desperate and annoyed.

    Eric
    Eric Robishaw, Dec 18, 2003
    #1
    1. Advertising

  2. Check to see if the control you added has the declration. Vs.net
    automatically puts this declaration for you, unless you added this control
    in html view and then switched to your code behind class.

    "Eric Robishaw" <> wrote in message
    news:...
    > What's the deal?
    >
    > If I place a control, a standard Web control (like a panel, or server-side
    > Table), onto a Web User Control I've created, I can't access the control
    > from the Code-Behind code.
    >
    > In the Page_Load event of the Web User Control, if I say:
    >
    > PlaceHolder1.Controls.Add (new LiteralControl ("<img src='bla.gif'>"));
    >
    > I get an error: Object null. And sure enough, PlaceHolder1 has no value
    > set.
    >
    > If I do a "This.Controls.Count" I get a big fat zero.
    >
    > What's the deal.
    >
    > Desperate and annoyed.
    >
    > Eric
    >
    >
    Alessandro Zifiglio, Dec 18, 2003
    #2
    1. Advertising

  3. Eric Robishaw

    Fraggle Guest

    "Eric Robishaw" <> wrote in message news:<>...
    > What's the deal?
    > <cut>
    > In the Page_Load event of the Web User Control, if I say:
    >
    > PlaceHolder1.Controls.Add (new LiteralControl ("<img src='bla.gif'>"));
    >
    > I get an error: Object null. And sure enough, PlaceHolder1 has no value
    > set.
    ><snip>
    > Eric


    Try doing the action in page_init.

    i have no idea why, but it works for me!

    My lack of understanding of how asp.net works i expect!

    fragg
    Fraggle, Dec 18, 2003
    #3
    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. huobazi
    Replies:
    1
    Views:
    668
    David Waz...
    Jul 3, 2003
  2. Replies:
    1
    Views:
    361
  3. Shawn
    Replies:
    8
    Views:
    389
    Shawn
    Sep 28, 2006
  4. Steven D'Aprano
    Replies:
    42
    Views:
    1,122
    Terry Reedy
    Sep 28, 2008
  5. Event not firing in usercontrol inside usercontrol

    , Dec 10, 2004, in forum: ASP .Net Building Controls
    Replies:
    0
    Views:
    170
Loading...

Share This Page