【发布时间】:2018-10-11 11:01:40
【问题描述】:
在我的表单中,我的选择控件和文本框很少。我想在从数据库中获取值的文本框中显示自动完成选项。数据库中有更多记录,因此我通过从相同形式的下拉列表中获取值来过滤记录。我正在使用 jquery 自动完成功能。但它不起作用。当我单击该文本框时,什么都没有发生。
<asp:DropDownList ID="Cmb_PrdCat" runat="server" Height="38px" ToolTip= "Product category" Width="320px" ForeColor="#666666" CssClass="RoundedBtn" TabIndex="4" >
</asp:DropDownList>
<asp:DropDownList ID="Cmb_Domain" runat="server" Height="38px" Width="321px" ForeColor="#666666" CssClass="RoundedBtn" TabIndex="3" >
</asp:DropDownList>
<asp:DropDownList ID="Cmb_Reg" runat="server" Height="38px" Width="321px" ForeColor="#666666" CssClass="RoundedBtn" TabIndex="3" >
</asp:DropDownList>
<asp:TextBox ID="EndClient_Txt" runat="server" Width="317px"
Font-Names="Calibri" Font-Size="Medium" ForeColor="#666666"
Height="31px" CssClass="RoundedBtn" TabIndex="8" onfocus="SearchText()"></asp:TextBox>
jQuery函数:
<link href="jquery/jquery-ui.css" rel="stylesheet" type="text/css" />
<script src="jquery/jquery.min.js" type="text/javascript"></script>
<script src="jquery/jquery-ui.min.js" type="text/javascript"></script>
<script type="text/javascript">
function SearchText() {
$("#EndClient_Txt").autocomplete({
source: function(request, response) {
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "SalesOrderInput.aspx/GetClientName",
dataType: "json",
success: function(data) {
response(data.d);
},
error: function(result) {
alert("No Match");
}
});
}
});
}
</script>
在我的 aspx.vb 页面中,我的代码如下:
Public Function GetClientName() As List(Of String)
Dim empResult As List(Of String) = New List(Of String)()
Sql = "SELECT * FROM opportunities where PCategory ='" & Cmb_PrdCat.SelectedItem.Text & "' and Domain ='" & Cmb_Domain.SelectedItem.Text & "' and Region='" & Cmb_Reg.SelectedItem.Text & "'"
Dim cmd = New MySqlCommand(Sql, conn1)
reader = cmd.ExecuteReader()
While (reader.Read())
empResult.Add(reader("OppName").ToString())
End While
reader.Close()
Return empResult
End Function
当我开始在该文本框中输入内容时,会出现错误警报消息。
【问题讨论】:
-
看起来像 Web-Forms 控件,对吗?如果是这样,您设置到文本框的 ID 是服务器端 ID,但不一定是客户端 ID。您需要客户端 ID 才能将 jQuery 自动完成添加到文本框。
-
你的意思是说,调试器/游标没有到达ajax内部的“成功”或“错误”函数?
-
我的意思是选择器
$('#EndClient_Txt')在页面(客户端)上找不到任何控件,因为客户端控件名称对于 Web 表单控件会有所不同。 -
是的,这些控件来自 System.Web.UI.Controls。我在 aspx 页面中设置的 id 是 EndClient_Txt。当我单击文本框时,它甚至不显示“错误”警报。如果我在 "$("#EndClient_Txt").autocomplete({" 上方有警报消息。当我点击文本框时,此警报消息将不断发生。
-
尝试在Ajax中添加“数据”作为参数。
标签: asp.net vb.net webforms jquery-ui-autocomplete