如何解决我的JQueryAutocomplete将在ASP Net WebForm中工作
我遇到了一个小问题,我的JQuery没有显示自动完成列表
我得到一张表格,该表格通过第一个“ Contrat of Contrat”(中间数字)或“ Middle”(中间)数字向客户显示他刚刚拥有的一个矛盾
我的JQuery
$(document).ready(function() {
SearchText();
});
function SearchText() {
$("#txtEmpName").autocomplete({
source: function(request,response) {
$.ajax({
type: "POST",contentType: "application/json; charset=utf-8",url: "Default.aspx/GetEmployeeName",data: "{'empName':'" + document.getElementById('txtEmpName').value + "'}",dataType: "json",success: function(data) {
response(data.d);
},error: function(result) {
alert("No Match");
}
});
}
});
}
</script>
我的ASP网络
[WebMethod]
public static List<string> GetEmp(string empdetails)
{
string id_client = HttpContext.Current.Session["id_client"].ToString();
List<string> emp = new List<string>();
string strcon = ConfigurationManager.ConnectionStrings["con"].ConnectionString;
SqlConnection con = new SqlConnection(strcon);
if (con.State == ConnectionState.Closed)
{
con.Open();
}
string sqlquery = string.Format("select Num_contrat from [dbo].[Contrat] where Num_contrat LIKE '%'"+empdetails+"'%' and ClientNum_Client= '" + id_client + "' ",empdetails);
SqlCommand sqlcomm = new SqlCommand(sqlquery,con);
SqlDataReader sdr = sqlcomm.ExecuteReader();
while(sdr.Read())
{
emp.Add(sdr.GetString(0));
}
con.Close();
return emp;
}
AspNet
<asp:Button ID="Button1" runat="server" Text="Pas de Contrat" class="btn btn-dark mb-2 btn-sm" OnClientClick="javascript:return ShowHideDivOnButtonClick();" />
解决方法
如果txtEmpName
是asp.net Webform控件,则在运行时,它将被重命名为唯一名称。好消息是您可以通过<% txtEmpName.ClientID %>
更改您的代码,以便字段引用那些代码,并且所有字段都应工作。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。