title: ViewState list of objects c#
body: <p>hallo iam getting this error message when the page is load,</p>
  
  <p>Type 'messageBox' in Assembly 'App_Code.e9hyffkh, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' is not marked as serializable.</p>
  
  <p>iam new in asp.net , and i can find what iam going worng!</p>
  
  <p>heres my code:</p>
  
  <pre><code>public partial class home : System.Web.UI.Page
  {
  public string val = "";
  public string data = "";
  
  protected void Page_Load(object sender, EventArgs e)
  {
      val = "";
      if (!IsPostBack)
      {
          ViewState["Messages"] = new List&lt;messageBox&gt;();
      }
  
  }
  protected void ListBox1_SelectedIndexChanged(object sender, EventArgs e)
  {
  
  }
  protected void Button1_Click(object sender, EventArgs e)
  {
  
      var messages = (List&lt;messageBox&gt;)ViewState["Messages"];
  
      if (text1.Text == "")
      {
          val = "נא הכנס שם";
      }
      else
      {
          messages.Add(text1.Text);
          val = "נוסף בהצלחה";
      }
  
      ListBox1.DataSource = messages;
      ListBox1.DataBind();
      ViewState["Messages"] = messages;
      data = messages.Count.ToString();
  
      text1.Text = "";
  
  
  }
  </code></pre>