CreateChildControls issue with custom control
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 EnsureChild开发者_JAVA百科Controls on the consumer page before using the custom control properties but no luck, still null.
This happens when is not postback.
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;
}
}
精彩评论