asp.net - 在 ASP.net 中单击文本框时如何调用自动完成 jquery 功能
问题描述
在我的表单中,我几乎没有选择控件和文本框。我想在文本框中显示从数据库中获取值的自动完成选项。数据库中有更多记录,因此我通过从下拉列表中以相同形式获取值来过滤记录。我正在使用 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
当我开始在该文本框中输入内容时,出现错误警报消息。
解决方案
尝试在上面添加 [PageMethod] 或 [WebMethod] 注释
Public Function GetClientName() As List(Of String)
End Function
推荐阅读
- gcc - 为什么动态库源代码应该使用与位置无关的代码编译?
- javascript - 如何为 swiperjs 插件使用类似 scrollTo 功能的东西
- python - 为什么我们在执行之前用python打印shellcode?
- asp.net-core - 在 Asp.Net Core 中使用 SMS 服务而不是电子邮件重置密码
- webpack - 为什么 sass-loader 抱怨 Bootstrap 的默认 _variables.scss 中的单元不兼容?
- python - 我正在尝试使用分类模型分别使用其标签数据集分析和训练 IDS 的数据集(mirai 攻击)。我有这个错误
- angular - Angular Jasmine 测试:无法测试材料表按钮的单击事件
- python - 如何在 python kivy 中访问不同屏幕的变量?
- awk - AWK 在詹金斯中抛出“失控字符串常量”错误
- python-3.x - 无法将 Plotly 图表保存到 HTML 文件