title: ASP.NET C#, need to press a button twice to make something happen
body: <p>I got a web application, the problem is that the text in the label will not update on the first click, I need to click the button twice, I debugged to code, and I found out that the label does not recive the data until after the second click,</p>
  
  <p>Here is my code:</p>
  
  <pre><code>System.Data.SqlClient.SqlCommand command = new System.Data.SqlClient.SqlCommand();
  System.Data.SqlClient.SqlConnection connection;
  string CommandText;
  string game;
  string modtype;
  bool filter;
  protected void Page_Load(object sender, EventArgs e)
  {
  
      labDownloadList.Text = null;
  
      //Session variables:
      if (Session["Game"] != null)
      {
          game = Convert.ToString(Session["Game"]);
      }
      if (Session["ModType"] != null)
      {
          modtype = Convert.ToString(Session["ModType"]);
      }
      if (Session["FilterBool"] != null)
      {
          filter = Convert.ToBoolean(Session["FilterBool"]);
      }
      string ConnectionString = "Data Source=.\\SQLEXPRESS;AttachDbFilename=C:\\inetpub\\wwwroot\\stian\\App_Data\\Database.mdf;Integrated Security=True;User Instance=True";
      connection = new System.Data.SqlClient.SqlConnection(ConnectionString);
      System.Data.SqlClient.SqlDataReader reader;
      command = connection.CreateCommand();
      connection.Open();
      CommandText = "SELECT * FROM Command";
      if (filter)
      {
          CommandText = "SELECT * FROM Command WHERE Game='" + game + "' AND Type='" + modtype + "'";
      }
      command.CommandText = CommandText;
      reader = command.ExecuteReader();
      labDownloadList.Text = "";
      while (reader.Read())
      {
          string game = reader.GetString(1);
          string author = reader.GetString(2);
          string downloadlink = reader.GetString(3);
          string size = reader.GetString(4);
          string description = reader.GetString(5);
          string version = reader.GetString(6);
          string screenshotlink = reader.GetString(7);
          Int64 AmountDownloaded = reader.GetInt64(8);
  
          labDownloadList.Text += "Game: " + game + "&lt;br&gt;";
          labDownloadList.Text += "Author: " + author + "&lt;br&gt;";
          labDownloadList.Text += "Size: " + size + "&lt;br&gt;";
          labDownloadList.Text += "Description: " + description + "&lt;br&gt;";
          labDownloadList.Text += "Version: " + version + "&lt;br&gt;";
          labDownloadList.Text += "&lt;img src='" + screenshotlink + " /&gt;&lt;br&gt;";
          labDownloadList.Text += "Downloaded: " + AmountDownloaded + " times&lt;br&gt;&lt;hr&gt;";
          labDownloadList.Text += "&lt;a href='" + downloadlink + "'&gt;Download&lt;/a&gt;&lt;br&gt;";
      }
  }
  
  protected void Page_UnLoad(object sender, EventArgs e)
  {
      Session["Game"] = game;
      Session["ModType"] = modtype;
      Session["FilterBool"] = filter;
      connection.Close();
  }
  
  protected void btnFilter_Click(object sender, EventArgs e)
  {
      game = lstGames.SelectedValue;
      modtype = lstTypeMod.SelectedValue;
      filter = true;
  }
  </code></pre>