title: Property or indexer '' cannot be assigned to -- it is read only
body: <p>I have a class that is a list of class objects.</p>
  
  <pre><code>[Serializable]
  public class UserRequestOrders
  {
      private List&lt;RTORequestOrder&gt; m_thisUsersOrders = new List&lt;RTORequestOrder&gt;();
  
      public List&lt;RTORequestOrder&gt; RequestOrders
      {
          get { return m_thisUsersOrders; }
          set { m_thisUsersOrders = value; }
      }
  }
  </code></pre>
  
  <p>When I create an instance of this object I need to populate the list variable When m_thisUsersOrders with an existing list of requests (from a viewstate). </p>
  
  <pre><code>MyOrders.RequestOrders = (List&lt;RTODataEntryObjects.RTORequestOrder&gt;)ViewState["vsMyOrders"];
  </code></pre>
  
  <p>When the page posts back, I cast the viewstate into a list of RTORequestOrder objects, and try to set the RequestOrders property, I get the message that the property or indexer cannot be assigned to.  I have a "SET" accessor for the property.</p>
  
  <p>All posts that I have read on this topic state that I need to modify scope in the application settings, but I am not sure how that applies here.  I don't have any application settings set.</p>
  
  <p>I am hoping someone can help me understand how I can populate the list from an existing list.</p>
  
  <p>EDIT: Nico, Thanks for your response!  Below is the full code from the code behind page.  "MyOrders" and "lst" are essentially the same thing. When I am working with "lst" everything works the way that I want it to.  The reason that I want to use the "MyOrders" object instead is because I have a method that returns the list as a datatable with only the fields I need to display. (I didnt' show that code because the issue appears to be with the "SET" accessor.) "lst" has the same signiture as the "MyOrders.RequestOrders".  Why can I cast the the viewstate into the lst object, but not the MyOrders object?</p>
  
  <p>EDIT: Grant, thanks for your response as well.  I don't know how to set breakpoints for ASP pages...  :(</p>
  
  <pre><code>public partial class Default3 : System.Web.UI.Page
  {
  RTODataEntryObjects.UserRequestOrders MyOrders = new RTODataEntryObjects.UserRequestOrders();
  List&lt;RTODataEntryObjects.RTORequestOrder&gt; lst = new List&lt;RTODataEntryObjects.RTORequestOrder&gt;();
  
  
  void Page_PreRender(object sender, EventArgs e)
  {
      if (ViewState["vsMyOrders"] == null)
      {
          NewDataGrid.DataSource = (RTODataEntryObjects.UserRequestOrders)ViewState["vsMyOrders"];  // code to show the data in the grid when page loading
      }
  }
  
  protected void Page_Load(object sender, EventArgs e)
  {
  
      NewDataGrid.EnableViewState = true;
      NewDataGrid.DataSource = (RTODataEntryObjects.UserRequestOrders)ViewState["vsMyOrders"];
      NewDataGrid.DataBind();
  
  }
  
  public void btnSubmit(object sender, EventArgs e)
  {
  
      int id = Int32.Parse(TextBox1.Text); // dynamically getting the data from the frontend.
      string name = TextBox2.Text; // dynamically getting the data from the frontend.
      if (ViewState["vsMyOrders"] != null) // if the view state is already having data then can update the list and assign again to the viewstate later.
      {
          lst = (List&lt;RTODataEntryObjects.RTORequestOrder&gt;)ViewState["vsMyOrders"];
          MyOrders.RequestOrders = (List&lt;RTODataEntryObjects.RTORequestOrder&gt;)ViewState["vsMyOrders"];
      }
      RTODataEntryObjects.RTORequestOrder thisOrder = new RTODataEntryObjects.RTORequestOrder(id, name, User.Identity.Name, System.Environment.MachineName);
  
      lst.Add(thisOrder); // 
      MyOrders.AddNew(thisOrder);
  
      ViewState["vsMyOrders"] = MyOrders;
      NewDataGrid.DataSource = (IList&lt;RTODataEntryObjects.RTORequestOrder&gt;)ViewState["vsMyOrders"];
      NewDataGrid.DataBind();
  }
  }
  </code></pre>