title: Getting control value when switching a view as part of a multiview
body: <p>I have the following code in my aspx page:</p>
  
  <pre><code>&lt;asp:Button id="display_button" runat="server" Text="Display" OnClick="Button1_Click" /&gt; &amp;nbsp;
  &lt;asp:Button id="edit_button" runat="server" Text="Edit" OnClick="Button2_Click" /&gt; &amp;nbsp; 
  &lt;asp:Button id="save_button" runat="server" Text="Save" OnClick="Button3_Click" Visible="false" /&gt; &amp;nbsp; 
  
  &lt;asp:MultiView id="MultiView1" runat="server" ActiveViewIndex="0"&gt;
      &lt;asp:View id="View1" runat="server"&gt;
          &lt;asp:FormView id="view_program" runat="server"&gt; 
          &lt;ItemTemplate&gt;
              &lt;%# Eval("status").ToString().Trim() %&gt;
          &lt;/ItemTemplate&gt;
          &lt;/asp:FormView&gt;
      &lt;/asp:View&gt;
      &lt;asp:View id="View2" runat="server"&gt;
          &lt;asp:FormView id="edit_program" runat="server"&gt; 
          &lt;ItemTemplate&gt;
              &lt;asp:DropDownList id="p_status" runat="server"&gt;
              &lt;/asp:DropDownList&gt;
          &lt;/ItemTemplate&gt;
          &lt;/asp:FormView&gt;
      &lt;/asp:View&gt;
  &lt;/asp:MultiView&gt;  
  </code></pre>
  
  <p>and the following functions attached to the buttons in the code-behind page:</p>
  
  <pre><code>protected void Button1_Click(object sender, EventArgs e)
  {
      MultiView1.SetActiveView(View1);
      save_button.Visible = false;
  }
  
  protected void Button2_Click(object sender, EventArgs e)
  {
      MultiView1.SetActiveView(View2);
      save_button.Visible = true;
  }
  
  protected void Button3_Click(object sender, EventArgs e)
  {
      DropDownList p_status = edit_program.FindControl("p_status") as DropDownList;
      var status = p_status.SelectedValue;
      Label1.Text = status;
      //save_button.Visible = false;
      //MultiView1.SetActiveView(View1);
  }
  </code></pre>
  
  <p>The idea being, that there are two views, the first displays the information, if the user wants to edit the information, they click button 2 which changes the view to the edit mode, which has the controls (drop downs, text fields, etc). It also makes the 'save' button appear.</p>
  
  <p>What I am trying to make happen is, when the save button is clicked, it will grab all of the values from the various fields, update the object and then update the database. Then it would flip back to view1 with the updated info.</p>
  
  <p>Problem is, as you can see in <code>void Button3_Click</code>, I try grab the values from the control, p_status, but it only gets the original value. example, the menu has three values, 'Green', 'Yellow', and 'Red'. Green is the default value and is selected when view2 is displayed. However, if I select Yellow or Red, and click save, rather than the label being updated to display one of those two values, it always displays Green. </p>
  
  <p>Any ideas?</p>
  
  <p>edit: page load function per request below</p>
  
  <pre><code>protected void Page_Load(object sender, EventArgs e)
  {
      try
      {
      Person myPerson = new Person(userid);
      TestProgram myProgram = new TestProgram(id);
  
      List&lt;TestProgram&gt; program = new List&lt;TestProgram&gt; { myProgram };
  
      view_program.DataSource = program;
      view_program.DataBind();
      edit_program.DataSource = program;
      edit_program.DataBind();
  
  
      DropDownList p_status = edit_program.FindControl("p_status") as DropDownList;
      p_status.Items.Add(new ListItem("Green", "Green"));
      p_status.Items.Add(new ListItem("Yellow", "Yellow"));
      p_status.Items.Add(new ListItem("Red", "Red"));
      //myProgram.Status = "Red";
      p_status.SelectedValue = myProgram.Status;
  
      }
      catch (Exception ex)
      {
      Response.Write(ex);
      Label1.Text = ex.ToString();
  
      }
  
  }
  </code></pre>