views:

16

answers:

1

Hi,
I have a custom control that creates a textbox on CreateChildControls.

I'm trying to set the value of this textbox (trough a property of the control) on the load event of the page that uses the custom control. Unfortunately at this point CreateChildControls haven't been executed yet and the textbox is null.

I called EnsureChildControls on the consumer page before using the custom control properties but no luck, still null.

This happens when is not postback.

+1  A: 

You need to call EnsureChildControls from within the property getter of your custom control to ensure it's built before accessing a nested control. If that doesn't help post some code so we can see what you are doing.

Public string Text
{
   get
   {
      EnsureChildControls();
      return textBox1.Text;
   }
   set
   {
      EnsureChildControls();
      textBox1.Text = value;
   }
}
TheCodeKing
That did it. Thanks!
Timmy O' Tool