How can I clear viewstate of a dropdownlist inside a usercontrol? Should I?
Posted
by tbilly
on Stack Overflow
See other posts from Stack Overflow
or by tbilly
Published on 2010-04-16T16:41:54Z
Indexed on
2010/04/16
16:43 UTC
Read the original article
Hit count: 250
I have a web user control with a dropdownlist inside of it. When the usercontrol's databind event is called, it automatically fires the dropdownlists databind event. In the dropdownlist's ondatabound event handler an 'other' option is appended to the end of the dropdownlist. The usercontrol is loaded multiple times, depending on selection of other controls on the page. When the page loads initially, there are no items in the usercontrol except the 'other' option. Then when I call the user control's databind event the control reloads, with 4 items plus the 'other' option. The text for the first item in the list is the 'other' option's text, not what it should be. I've stepped through the databound event of the dropdownlist and have found that all items are loading correctly. It appears that the dropdownlist's viewstate is the culprit, that the dropdownlist's original item[1] text is overwriting the new text. I've tried disabling viewstate on the dropdownlist, but then it wouldn't load at all.
Should I try to clear the dropdownlist's viewstate? How do I do that?
Any suggestions would be greatly appreciated.
© Stack Overflow or respective owner