title: How to call c# method with user Authenticator from asp.net site
body: <p>I don't have any idea how to call code-behind method where I verify logged user to set his list of items and then display it on asp.net web controls like lables runat server.</p>
  
  <p>I read some post where they say use static method to call but if I do this I cannot  access to web controls then I read use findcontrol to get access but it returns null in controls 
  Any idea how i can do this ?</p>
  
  <p>Here is some code-behind and next one is ajax call to this </p>
  
  <pre><code>public static void JsRequest()
  {
      MembershipUser currentUser = Membership.GetUser();
      Guid currentUserId = (Guid)currentUser.ProviderUserKey;
      string guid = currentUserId.ToString();
      if (currentUser == null)
          currentUser = null;
      else
      {
          DataSet dsInsert2 = new DataSet();
          SqlDataReader reader2;
          SqlCommand cmdRead2 = new SqlCommand();
          SqlConnection coninsert2 = new SqlConnection(ConfigurationManager.ConnectionStrings["ImportsConn"].ToString());
          cmdRead2 = new SqlCommand("[usp_getMachines]", coninsert2) { CommandType = CommandType.StoredProcedure };
          cmdRead2.Parameters.AddWithValue("@UserID", guid); // Value 
          //cmdRead.Parameters.AddWithValue("@StartDate", AspxStartDate.Date);   // Value 
          //cmdRead.Parameters.AddWithValue("@EndDate", AspxEndDate.Date);   // Value 
          cmdRead2.Connection = coninsert2;
          coninsert2.Open();
          // Do  Dates  from  DB 
          reader2 = cmdRead2.ExecuteReader();
          while (reader2.Read())
          {
              // Int32 RowNR = reader2.GetInt32(reader2.GetOrdinal(""))
              Int32 RowNR = reader2.GetInt32(reader2.GetOrdinal("RowNR"));
              Int32 MachineID = reader2.GetInt32(reader2.GetOrdinal("MachineID"));
              string MachineNr = reader2["MachineNr"] as string;
              DataSet dsInsert = new DataSet();
              SqlDataReader reader;
              SqlCommand cmdRead = new SqlCommand();
              SqlConnection coninsert = new SqlConnection(ConfigurationManager.ConnectionStrings["ImportsConn"].ToString());
              cmdRead = new SqlCommand("[usp_getJobShopDone]", coninsert) { CommandType = CommandType.StoredProcedure };
              cmdRead.Parameters.AddWithValue("@MachineID", MachineID); // Value 
              // cmdRead.Parameters.AddWithValue("@MachineID",  Request.QueryString.TExt("MachineID");   // Value 
              // cmdRead.Parameters.AddWithValue("@StartDate", AspxStartDate.Date);   // Value 
              // cmdRead.Parameters.AddWithValue("@EndDate", AspxEndDate.Date);   // Value 
              cmdRead.Connection = coninsert;
              coninsert.Open();
              // Do  Dates  from  DB 
              reader = cmdRead.ExecuteReader();
              while (reader.Read())
              {
                  Page page = (Page)HttpContext.Current.Handler;
                  System.Web.UI.WebControls.Label Label4 = (System.Web.UI.WebControls.Label)page.FindControl("Label4");
                  System.Web.UI.WebControls.Label Label1 = (System.Web.UI.WebControls.Label)page.FindControl("Label1");
                  System.Web.UI.WebControls.Label Label2 = (System.Web.UI.WebControls.Label)page.FindControl("Label2");
                  System.Web.UI.WebControls.Label Label3 = (System.Web.UI.WebControls.Label)page.FindControl("Label3");
                  HtmlImage img1 = (HtmlImage)page.FindControl("img1");
                  HtmlImage img2 = (HtmlImage)page.FindControl("img2");
                  HtmlImage img3 = (HtmlImage)page.FindControl("img3");
                  System.Web.UI.WebControls.Label LabeMachine1 = (System.Web.UI.WebControls.Label)page.FindControl("LabeMachine1");
                  System.Web.UI.WebControls.Label LabeMachine2 = (System.Web.UI.WebControls.Label)page.FindControl("LabeMachine2");
                  System.Web.UI.WebControls.Label LabeMachine3 = (System.Web.UI.WebControls.Label)page.FindControl("LabeMachine3");
                  Label4.Text = reader["CurrentStatus"] as string;
                  //  MessageBox.Show(RowNR.ToString());
                  if (Label4.Text == "Active" &amp;&amp; RowNR == 1)
                  {
                      img1.Src = "~/Images/kafle/kafle_zebatka-05.svg";
                      LabeMachine1.Text = reader["MachnineName"] as string;
                      Label1.Text = reader["CurrentStatus"] as string;
                      page.Session["M1"] = MachineID;
                  }
                  else if (Label4.Text == "Standby" &amp;&amp; RowNR == 1)
                  {
                      img1.Src = "~/Images/kafle/kafle_zebatka-06.svg";
                      LabeMachine1.Text = reader["MachnineName"] as string;
                      Label1.Text = reader["CurrentStatus"] as string;
                      page.Session["M1"] = MachineID;
                  }
                  else if (Label4.Text == "Error" &amp;&amp; RowNR == 1)
                  {
                      img1.Src = "~/Images/kafle/kafle_zebatka-01.svg";
                      LabeMachine1.Text = reader["MachnineName"] as string;
                      Label1.Text = reader["CurrentStatus"] as string;
                      page.Session["M1"] = MachineID;
                  }
                  else if (Label4.Text == "Setting" &amp;&amp; RowNR == 1)
                  {
                      img1.Src = "~/Images/kafle/kafle_zebatka-03.svg";
                      LabeMachine1.Text = reader["MachnineName"] as string;
                      Label1.Text = reader["CurrentStatus"] as string;
                      page.Session["M1"] = MachineID;
                  }
                  else if (Label4.Text == "Emergency Stop" &amp;&amp; RowNR == 1)
                  {
                      img1.Src = "~/Images/kafle/kafle_status-yel-yel.svg";
                      LabeMachine1.Text = reader["MachnineName"] as string;
                      Label1.Text = reader["CurrentStatus"] as string;
                      page.Session["M1"] = MachineID;
                  }
              }
  </code></pre>
  
  <pre class="lang-js prettyprint-override"><code>function getState() {
    try {
      $.ajax({
        type: "POST",
        url: "HeadMenu.aspx/JsRequest",
        contentType: "application / json; charset = utf - 8",
        dataType: "JSON",
        success: function(response) {
          alert(response);
        },
        error: function(response) {
          alert("something wrong")
        }
      });
    } catch (err) {}
  }
  </code></pre>