C
cmay
A common situation I come across is an ASCX control that being used as
a lookup control.
The ascx might be called "StatusLookup" or something, and it consists
of 1 dropdown list that populates itself from cache/database list.
If you databind on the Init event, then you are databinding every time,
and not making any use of the viewstate.
If you databind on the Load event, you can see if the control has
already been loaded by the viewstate, but if you have code in your
pages Load event, that can run before the Load event on your ASCX
control is fired.
So, you can end up with a situation where you PAGE load method is
trying to set the value of the dropdown in the ASCX, but the ASCX has
not yet databound.
I have always written some code to work around this situation, using a
series of checks to see if items have been added to the dropdown or
not, but I am wondering if there is a better pattern to be followed
when doing something like this.
a lookup control.
The ascx might be called "StatusLookup" or something, and it consists
of 1 dropdown list that populates itself from cache/database list.
If you databind on the Init event, then you are databinding every time,
and not making any use of the viewstate.
If you databind on the Load event, you can see if the control has
already been loaded by the viewstate, but if you have code in your
pages Load event, that can run before the Load event on your ASCX
control is fired.
So, you can end up with a situation where you PAGE load method is
trying to set the value of the dropdown in the ASCX, but the ASCX has
not yet databound.
I have always written some code to work around this situation, using a
series of checks to see if items have been added to the dropdown or
not, but I am wondering if there is a better pattern to be followed
when doing something like this.