Dawood Abbas

Dawood Abbas

  • NA
  • 264
  • 98.2k

c# how to get asp.net textbox value inside static web method

Aug 22 2015 3:10 AM
I want to call c# methode from javascript timer like below.

Hide Copy Code
<script type="text/javascript">           window.setInterval(DeleteKartItems, 10000);           function DeleteKartItems() {             PageMethods.DeleteItem();             alert("test");         }     </script> 

c# methodes

Hide Copy Code
public static void DeleteItem()         {                string query = "[Get_Messages]";             SqlCommand cmd = new SqlCommand(query);             cmd.CommandType = CommandType.StoredProcedure;             cmd.Parameters.AddWithValue("@roomId", 5);             GetData(cmd);         }           private static void GetData(SqlCommand cmd)         {             string strConnString = ConfigurationManager.ConnectionStrings["LinqChatConnectionString"].ConnectionString;             using (SqlConnection con = new SqlConnection(strConnString))             {                 using (SqlDataAdapter sda = new SqlDataAdapter())                 {                     cmd.Connection = con;                     sda.SelectCommand = cmd;                     using (DataSet ds = new DataSet())                     {                         sda.Fill(ds, "Messages");                     }                 }             }         }

so how to get label/TextBox value inside above methodes?

I tried like below but its getting null value..

Hide Copy Code
Page page = HttpContext.Current.Handler as Page;             Label lblRoomId = (Label)page.FindControl("lblRoomId");             string lbRoomId = lblRoomId.Text;

Answers (3)