假設我有一個textbox1,它具有一些值,例如日期。現在我有另一個textbox2,它有autocompleteextender,它的值是通過web方法定義的。現在我想要在webmethod中定義的變量應該從textbox1中獲取值。將文本框值解析爲asp.net中web方法中定義的變量
[System.Web.Script.Services.ScriptMethod(), System.Web.Services.WebMethod()]
public static List<string> SearchVehicles(string prefixText, int count)
{
MySqlConnection conn = new MySqlConnection();
conn.ConnectionString = ConfigurationManager.ConnectionStrings("conio").ConnectionString;
MySqlCommand cmd = new MySqlCommand();
cmd.CommandText = "SELECT flightNo FROM flight_train where (freq like @freq) and status = 'active'";
cmd.Parameters.AddWithValue("@freq", "%" + prefixText + "%");
cmd.Connection = conn;
conn.Open();
List<string> strVehicle = new List<string>();
MySqlDataReader sdr = cmd.ExecuteReader;
while (sdr.Read) {
strVehicle.Add(sdr("flightNo").ToString);
}
conn.Close();
return strVehicle;
}
在上面的WebMethod變量(prefixText)的定義,我想從TextBox1的取值
您必須在javascript/JQuery的SearchVehicles調用中傳遞textbox1值。 – Adil
@Adil你可以請分享一個參考鏈接或張貼在答案如何做到這一點? – SUN
@Adil是否有可能在session或viewstate中存儲textbox1值,然後在webmethod中檢索該值? – SUN