Running CreateChildren automatically on hidden server control

C

Chris Smith

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.
 
J

John Saunders

Chris Smith said:
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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top