How to hold the list of Data in Viewstate of asp.net ?


Hi

While working on one of personal project there was requirement to hold the collection of data of some event and again i have to validate that data on some other event, then i did using Viewstate like this sample code


 protected void Button1_Click(object sender, EventArgs e)
        {
            ViewStateList.Add(1);
            ViewStateList.Add(5);
        }
        protected List<int> ViewStateList
        {
            get
            {
                if (ViewState["Record"] == null) ViewState["Record"] = new List<int>();
                return (List<int>)ViewState["Record"];
            }
        }
        protected void Button2_Click(object sender, EventArgs e)
        {
            foreach (int n in ViewStateList)
            {
                Response.Write(n);
            }
        }

I hope this will help to somebody.

Advertisement

One thought on “How to hold the list of Data in Viewstate of asp.net ?

  1. blog search June 5, 2014 / 4:43 am

    This is my first time pay a visit at here and i am truly happy to read all at alone place.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.