首页 > 解决方案 > 在 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

当我开始在该文本框中输入内容时,出现错误警报消息。

标签: asp.netvb.netwebformsjquery-ui-autocomplete

解决方案


尝试在上面添加 [PageMethod] 或 [WebMethod] 注释

Public Function GetClientName() As List(Of String)

End Function

推荐阅读