title: Code behind not taking the current text from dropdown
body: <p>I have a problem with my button and dropdown, when I click the button and a method is called in the code behind, the code behind is not taking the current text of the dropdown, but the text after the refresh of the site. The aspx code for this is:</p>
  
  <pre><code>&lt;form id="form1" runat="server"&gt;
      &lt;asp:ScriptManager ID="ScriptManager" EnablePageMethods="true" runat="server" /&gt;
  &lt;div&gt;
      &lt;table runat="server" id="showDBTable"&gt;
          &lt;tr&gt;
              &lt;td&gt;
                  &lt;asp:Button ID="showDB" runat="server" OnClick="showDBContent" Text="Show database content" /&gt;
              &lt;/td&gt;
              &lt;td&gt;
                  &lt;asp:DropDownList runat="server" ID="showDBDropDown" OnLoad="FindExistingMetaTag" /&gt;
              &lt;/td&gt;
          &lt;/tr&gt;
      &lt;/table&gt;
  &lt;/div&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>and the code behind:</p>
  
  <pre><code>protected void showDBContent(object sender, EventArgs e)
  {
      String queryString = "";
      if (showDBDropDown.Text == "Show all")
      {
          queryString = "SELECT * from dbo.Search";
      }
      else
      {
          queryString = "SELECT * from dbo.Search where Tag = '" + (showDBDropDown.Text).TrimStart().TrimEnd() + "'";
      }
  </code></pre>
  
  <p>How do I work around that?</p>
  
  <p>Edit - As requested:</p>
  
  <pre><code>    protected void FindExistingMetaTag(object sender, EventArgs e)
  {
      String queryString = "SELECT TAG from dbo.Tags";
      List&lt;String&gt; tagsShow = new List&lt;String&gt;();
      tagsShow.Add("Show all");
      using (SqlConnection conn = new SqlConnection(info.connectionString))
      using (var cmd = conn.CreateCommand())
      {
          conn.Open();
          cmd.CommandText = queryString;
          using (SqlDataReader reader = cmd.ExecuteReader())
          {
              while (reader.Read())
              {
                  tagsShow.Add(reader.GetString(0));
              }
          }
      }
  
      showDBDropDown.DataSource = tagsShow;
      showDBDropDown.DataBind();
      showDBDropDown.SelectedIndex = 0;
  }
  </code></pre>
  
  <p>I just noticed it might have been "showDBDropDown.SelectedIndex = 0;", but it does not seem to change anything to remove it.</p>