All controls are still null after calling EnsureChildControls()?
The way this page is laid out, all of the data is loaded at Page_Init
. Well, I have a custom control that is having problems with this though.
I have it on the page like so:
<cc:SomeControl... />
And then I set the value at Page_Init using
MyControl.Value="blah";
Simple stuff..
The Value
is an accessor and has something similar to this:
public string Value{
get...
set{
En开发者_如何学运维sureChildControls();
MyHiddenField.Value=value;
}
}
and it is here that I have a problem. It says that MyHiddenField
is null. Is Page_Init
just too early for this? Or is there some other function I need to call?
The fix for this was changing from using a namespace to reference the CustomControl to using a src
with a filename
changing this:
<%@ Register Assembly="MyProduct" Namespace="MyProduct.CustomControls" TagPrefix="cc" %>
to this:
<%@ Register src="/CustomControls/MyControl.ascx" tagname="MyControl" tagprefix="uc2" %>
精彩评论