title: Pass Values Between aspx webpage and class
body: <p>I am wondering how to call a Label from a certain aspx page in another cs file. For example:</p>
  
  <pre><code>protected void Button1_Click(object sender, EventArgs e)
      {
          Test1.Insert1(this);
      }
  </code></pre>
  
  <p>This code i have in the Something.aspx.cs file to call a method from another cs file i created which looks like:</p>
  
  <pre><code>public static class Test1 
  {
      public static void Insert1(System.Web.UI.Page Ins)
  
       {
          string conn = "Data Source=pc-...";
          System.Data.SqlClient.SqlConnection sqlConn = new System.Data.SqlClient.SqlConnection(conn);
          if (Page.IsValid)
          {
              try
              {
                  sqlConn.Open();
                  Ins.LabelAdd.Text = "Worked!";
                  System.Data.SqlClient.SqlCommand myCommand = new System.Data.SqlClient.SqlCommand("INSERT INTO ... ", sqlConn);
                  myCommand.ExecuteNonQuery();
              }
              catch (Exception ex)
              {
                  Ins.LabelAdd.Text = "Error! " + ex;
              }
              finally
              {
                  sqlConn.Close();
              }
          }
      }
  }
  </code></pre>
  
  <p>But this doesn't work. I was able to do this before with a session but this won't work. I can't call the LabelAdd which I used in the Something.aspx page. Any ideas on how I can fix this? Thank you.</p>