View State for Custom DropDownList control
I'm having an issue maintaining a selected value on a custom DropDownList control. I figured if the viewstate property was enabled on the base control, everything would be all set, i've found that isn't the case. I think another question I have is maybe I should just be using the Request object to get/set the values? My control i开发者_开发问答s as follows.
[DefaultProperty("Text")]
[ToolboxData("<{0}:TicketStatusDropdownControl runat=server></{0}:TicketStatusDropdownControl>")]
public class TicketStatusDropdownControl : DropDownList
{
private string _defaultValue = string.Empty;
private string _selectedItem = string.Empty;
private string _selectedValue = string.Empty;
protected override void Render(HtmlTextWriter writer)
{
if (_defaultValue != string.Empty)
{
this.Items.Add(new ListItem(_defaultValue));
}
foreach (string item in TicketWorkflowStates.getWorkflowStates())
{
this.Items.Add(new ListItem(item));
}
base.Render(writer);
}
}
Try overriding the LoadViewState() and SaveViewState() methods - set and retrieve ViewState values there?
精彩评论