M
Mark Olbert
I have a composite control (under ASPNET2; derived from CompositeControl) which contains a label. The contents of the label are set
when the control is created to a user-supplied value.
What's confusing me is that on postback the contents of the label are not being restored from ViewState. I thought that happened
automagically...but I guess not. I'm obviously missing something really simple. How do I get the label to set its text from
ViewState on postback?
protected override void CreateChildControls()
{
Controls.Clear();
lblCtl = new Label();
lblCtl.ID = "questionLabel";
// UseStoredState is true on postback, false on initial creation
if( !UseStoredState )
{
lblCtl.Text = quesRow.text;
ViewState["questionId"] = quesRow.id.ToString();
}
Controls.Add(lblCtl);
}
when the control is created to a user-supplied value.
What's confusing me is that on postback the contents of the label are not being restored from ViewState. I thought that happened
automagically...but I guess not. I'm obviously missing something really simple. How do I get the label to set its text from
ViewState on postback?
protected override void CreateChildControls()
{
Controls.Clear();
lblCtl = new Label();
lblCtl.ID = "questionLabel";
// UseStoredState is true on postback, false on initial creation
if( !UseStoredState )
{
lblCtl.Text = quesRow.text;
ViewState["questionId"] = quesRow.id.ToString();
}
Controls.Add(lblCtl);
}