HiddenField.Value is an empty string upon postback inside my custom control
Posted
by
Matthew Cox
on Stack Overflow
See other posts from Stack Overflow
or by Matthew Cox
Published on 2011-01-17T17:48:41Z
Indexed on
2011/01/17
17:53 UTC
Read the original article
Hit count: 187
I have a custom control that has a hidden field. Upon postback I want to obtain the value stored in it, but it's always an empty string. any thoughts?
I am performing client-side manipulation of the hidden field values and have verified in firebug that the fields are correct before issue a post back
Here is the setup:
public class DualListPanel : SWebControl, INamingContainer
{
protected IList<DlpItem> UnassignedList { get; set; }
protected IList<DlpItem> AssignedList { get; set; }
private HiddenField assignedItemsField, unassignedItemsField;
public DualListPanel()
{
CssClass = "DualListPanel";
EnableViewState = true;
}
#region ViewState
protected override void LoadViewState(object savedState)
{
var state = savedState as object[];
UnassignedList = state[0] as List<DlpItem>;
AssignedList = state[1] as List<DlpItem>;
base.LoadViewState(state[2]);
}
protected override object SaveViewState()
{
object[] state = new object[3];
state[0] = UnassignedList;
state[1] = AssignedList;
state[2] = base.SaveViewState();
return state;
}
#endregion
#region WebControl Overrides
protected override void CreateChildControls()
{
assignedItemsField = new HiddenField();
assignedItemsField.ID = "HiddenAssignedItems";
assignedItemsField.EnableViewState = true;
unassignedItemsField = new HiddenField();
unassignedItemsField.ID = "HiddenUnassignedItems";
unassignedItemsField.EnableViewState = true;
Controls.Add(assignedItemsField);
Controls.Add(unassignedItemsField);
base.CreateChildControls();
}
#endregion
#region Item Lists Retrieval
public string GetCommaDelimUnassignedItems()
{
return unassignedItemsField.Value;
}
public string GetCommaDelimAssignedItems()
{
return assignedItemsField.Value;
}
#endregion
}
© Stack Overflow or respective owner