is it possible to store an array in a viewstate

Soyncroutty

New Member
is it possible to store an array in a viewstate? if not, how could you keep track of multiple values between postbacks?Well, here's some code where I did just that with an ArrayLIST, so I guess it must also be possible with an array.<BR><BR>JON<BR><BR><BR><BR><%@ Page Language="VB" debug="true" %><BR><BR><script language="VB" runat="server"><BR><BR> Dim myAL as new ArrayList()<BR><BR> Sub Page_Load(obj as object, e as eventargs)<BR> <BR> If IsNothing(ViewState("myAL")) then<BR> ViewState("myAL") = myAL<BR> end if<BR> <BR> ddDDL.DataSource = ViewState("myAL") <BR> <BR> If not Page.IsPostBack then<BR> myAL.Add("Item1")<BR> myAL.Add("Item2")<BR> myAL.Add("Item3") <BR> ddDDL.DataSource = myAL<BR> ddDDL.DataBind()<BR> end if<BR> end sub<BR> <BR> Sub AddToArrayList(obj as object, e as eventargs)<BR> myAL = ViewState("myAL")<BR> myAL.Add(tbTextBox.Text)<BR> ViewState("myAL") = myAL<BR> ddDDL.DataBind()<BR> end sub<BR> <BR><BR></script><BR><BR><html><BR><body><BR> <form runat="server"><BR> <asp:DropDownList id="ddDDL" runat="server" /><BR> <BR><BR> <asp:TextBox id="tbTextBox" runat="server" /><BR> <asp:Button runat="server" onclick="AddToArrayList" text="Add to ArrayList" /><BR> </form><BR></body><BR></html>
 
Back
Top