N
Nick
Hi,
I am developing a set of custom templated controls to clean up and unify the
design of our ASP.NET website. The controls are DataEntryPage,
DataEntrySection, DataEntryRow and DataEntryUnit, and are basically tables
with the appropriate CSS settings and whatever to keep it all nice and neat
and consistent.
My problem arises through the simple fact that when I place a DataEntryPage
(the outermost of the controls) into a UserControl, I get
NullReferenceExceptions when I try to access its controls through
server-side code. I have pinned this down to the fact that none of the
DataEntry controls have their CreateChildControls method called; the
constructors are called, but no CreateChildControls.
I can't understand why this is happening! Every other custom control I have
developed works perfectly as expected, what makes these ones different? The
simple fact that they have publically available ITemplate properties should
not cause this behaviour. So, I have created my own UserControl class which
overrides OnInit, and calls EnsureChildControls before I do anything else.
Sure enough, the CreateChildControls method of the UserControl is called,
but, for some unknown reason, the DataEntry units, and consequently their
contained controls, never have their CreateChildControls methods called.
Only with a manual search through UserControl.Controls for a DataEntryPage,
and then calling a publically available method called CreateControls (which
simply calls EnsureChildControls from within the DataEntryPage) on that
DataEntryPage, am I able to get the desired behaviour. Why?
Any help is appreciated.
Regards,
Nick
I am developing a set of custom templated controls to clean up and unify the
design of our ASP.NET website. The controls are DataEntryPage,
DataEntrySection, DataEntryRow and DataEntryUnit, and are basically tables
with the appropriate CSS settings and whatever to keep it all nice and neat
and consistent.
My problem arises through the simple fact that when I place a DataEntryPage
(the outermost of the controls) into a UserControl, I get
NullReferenceExceptions when I try to access its controls through
server-side code. I have pinned this down to the fact that none of the
DataEntry controls have their CreateChildControls method called; the
constructors are called, but no CreateChildControls.
I can't understand why this is happening! Every other custom control I have
developed works perfectly as expected, what makes these ones different? The
simple fact that they have publically available ITemplate properties should
not cause this behaviour. So, I have created my own UserControl class which
overrides OnInit, and calls EnsureChildControls before I do anything else.
Sure enough, the CreateChildControls method of the UserControl is called,
but, for some unknown reason, the DataEntry units, and consequently their
contained controls, never have their CreateChildControls methods called.
Only with a manual search through UserControl.Controls for a DataEntryPage,
and then calling a publically available method called CreateControls (which
simply calls EnsureChildControls from within the DataEntryPage) on that
DataEntryPage, am I able to get the desired behaviour. Why?
Any help is appreciated.
Regards,
Nick