D
Dave Weeden
Hi all,
I have a strange issue with dropdown items that I'm trying to understand.
We use dropdowns in three contexts:
1) directly specified in an aspx file
2) dynamically added to the controls collection of a server side table cell
of an aspx file
3) dynamically added to a custom class derived from WebControl that
implements INamingContainer (not a user control) that is in turn added to
the controls collection of another server side table cell of an aspx file
In each case we populate the option lists in the OnInit method.
In case #1, we noticed duplicate items were getting created on postbacks so
we put in a check so that the items were only populated when IsPostback was
false.
We followed the same methodology for case #2 and #3, figuring that we needed
to avoid creating duplicates.
Turns out the behaviour is quite different in these two latter cases:
Case #2: Does not produce the duplicates on postbacks and in fact will end
up with an empty option list unless it is repopulated each and every time
the page is loaded.
Case #3: Does not produce the duplicates on postbacks but will retain its
option list and therefore it doesn't matter whether the list is populated or
not on subsequent postbacks.
This basically boils down to case #1 needs to populate its list exactly
once, case #2 needs to populate its list every time, and case #3 needs to
populate its list at least once but more than that is ok as well.
The obvious workaround is deal with the behaviour on a case by case basis as
appropriate but I'd really like to understand what is going on behind the
scenes (especially why case #2 and case #3 are different).
Thanks in advance,
Dave
I have a strange issue with dropdown items that I'm trying to understand.
We use dropdowns in three contexts:
1) directly specified in an aspx file
2) dynamically added to the controls collection of a server side table cell
of an aspx file
3) dynamically added to a custom class derived from WebControl that
implements INamingContainer (not a user control) that is in turn added to
the controls collection of another server side table cell of an aspx file
In each case we populate the option lists in the OnInit method.
In case #1, we noticed duplicate items were getting created on postbacks so
we put in a check so that the items were only populated when IsPostback was
false.
We followed the same methodology for case #2 and #3, figuring that we needed
to avoid creating duplicates.
Turns out the behaviour is quite different in these two latter cases:
Case #2: Does not produce the duplicates on postbacks and in fact will end
up with an empty option list unless it is repopulated each and every time
the page is loaded.
Case #3: Does not produce the duplicates on postbacks but will retain its
option list and therefore it doesn't matter whether the list is populated or
not on subsequent postbacks.
This basically boils down to case #1 needs to populate its list exactly
once, case #2 needs to populate its list every time, and case #3 needs to
populate its list at least once but more than that is ok as well.
The obvious workaround is deal with the behaviour on a case by case basis as
appropriate but I'd really like to understand what is going on behind the
scenes (especially why case #2 and case #3 are different).
Thanks in advance,
Dave