Preserve View State value at post back


Hi All,
   I am creating a custom server control.That control contains a check box list. For the first time I am getting value for that check box list, at run time through Get/Set property. In Property I am using View state for setting value. While page is post back, the view state is getting null. How can I preserve the value of view state. Sample code is as follows, 
private CheckBoxList _chkList;protected override void CreateChildControls()
{
string strItems;
string[] StrArrItem = null;
char cSplitChar = ',';
int intLegth = 0;_chkList = new CheckBoxList();
_chkList.ID = "DDList";
_chkList.BorderColor = Color.White;
_chkList.BorderStyle = BorderStyle.Solid;
_chkList.Width = Unit.Percentage(100);
strItems = List;
StrArrItem = strItems.Split(cSplitChar);
intLegth = StrArrItem.Length;
 
for (int i = 0; i < intLegth; i++)
{
_chkList.Items.Add(StrArrItem[i]);
}
this.Controls.Add(_chkList);
}
 
public string List
{
get
{
 
strValue = ViewState["Value"].ToString();if (strValue.Length > 0)
{
strValue = strValue.Length > 0 ? strValue.Substring(0, strValue.Length - 1) : strValue;
}
 
return strValue;
}
set
{
ViewState["Value"] = null;
strValue += value + ",";
ViewState["Value"] = strValue;
 
}
}
Can anybody help me pleaseeeeSad

Regards,
Anu
1
AnuMaria
1/20/2009 4:46:17 AM
📁 asp.net.web-forms
📃 93655 articles.
⭐ 6 followers.

💬 1 Replies
👁️‍🗨️ 2367 Views



May be this link will help you..
http://msdn.microsoft.com/en-us/library/ms178651.aspx


My Blog


"Don't be afraid to be wrong; otherwise you'll never be right."
1
budugu
1/20/2009 5:32:38 AM
Reply: