Running CreateChildren automatically on hidden server control

Discussion in 'ASP .Net Building Controls' started by Chris Smith, Oct 26, 2004.

  1. Chris Smith

    Chris Smith Guest

    Hi
    I am getting what appears to me as incorrect behavior from my server
    control, but maybe its just that I don't fully understand the relationships
    involved.

    Here's the issue:

    I have a templated server control that overrides CreateChildren() method.
    However, if the control is hidden at page load (Visible="False" in the tag
    definition), the CreateChildren method doesn't seem to fire. That's fine. I
    wouldn't expect it to fire since its hidden.

    However, when I then set the control's visibility to true (inside a method
    on the page), the objects that should have been read from the template are
    still not available (they are <undefined>). If, on the other hand, I always
    set the control to be visible, everything works fine.

    To make this an easy flow, imagine it like this:
    Templated Server control, hidden on the ASPX page.
    If control is visible, then it runs the CreateChildren() method
    automatically to get the objects it needs from the template.
    If the control is hidden at startup, then MADE visible inside page code, the
    CreateChildren() never fires, so any operations done on objects that should
    have been created in CreateChildren are unavailable.

    Some help would be great on this one.
    Chris Smith, Oct 26, 2004
    #1
    1. Advertising

  2. "Chris Smith" <> wrote in message
    news:...
    > Hi
    > I am getting what appears to me as incorrect behavior from my server
    > control, but maybe its just that I don't fully understand the
    > relationships
    > involved.
    >
    > Here's the issue:
    >
    > I have a templated server control that overrides CreateChildren() method.
    > However, if the control is hidden at page load (Visible="False" in the tag
    > definition), the CreateChildren method doesn't seem to fire. That's fine.
    > I
    > wouldn't expect it to fire since its hidden.
    >
    > However, when I then set the control's visibility to true (inside a method
    > on the page), the objects that should have been read from the template are
    > still not available (they are <undefined>). If, on the other hand, I
    > always
    > set the control to be visible, everything works fine.


    When did you want CreateChildControls to be called? When are you trying to
    access the child controls? Whatever you're doing to access the child
    controls, EnsureChildControls() should be called in order to make sure the
    child controls are there.

    -----
    John Saunders
    John Saunders, Oct 27, 2004
    #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. neverstill
    Replies:
    3
    Views:
    7,383
    neverstill
    Jan 5, 2004
  2. Mike Labosh

    "Hidden" Web Server Control

    Mike Labosh, Dec 12, 2005, in forum: ASP .Net
    Replies:
    3
    Views:
    3,284
    =?Utf-8?B?U3VuZGFyLms=?=
    Dec 12, 2005
  3. Replies:
    2
    Views:
    5,025
    =?Utf-8?B?TGVvbiBNYXluZQ==?=
    Sep 4, 2006
  4. Rick
    Replies:
    3
    Views:
    8,091
    Alexey Smirnov
    Apr 13, 2010
  5. SolarCanine
    Replies:
    2
    Views:
    251
    SolarCanine
    Sep 20, 2005
Loading...

Share This Page