Ajax Autocomplete Extender - Passing more parameters to the server c#

 <asp:TextBox runat="server" ID="txtName" AutoPostBack="True" CssClass="form-control" OnTextChanged="txtName_TextChanged"></asp:TextBox>
                                    <asp:AutoCompleteExtender ID="AutoCompleteExtender1" runat="server" TargetControlID="txtName"
                                        EnableCaching="false"
                                        UseContextKey="true"
                                        BehaviorID="AutoCompleteCities"
                                        OnClientPopulating="autoComplete1_OnClientPopulating"
                                        ServiceMethod="GetItem" ServicePath="RequisitionUI.aspx" MinimumPrefixLength="1" CompletionInterval="500" CompletionSetCount="10"
                                        FirstRowSelected="true">
                                    </asp:AutoCompleteExtender>
 <asp:HiddenField ID="hdfAssetType" runat="server" />
   <script type="text/javascript">
        function autoComplete1_OnClientPopulating(sender, args) {
            sender.set_contextKey($("#" + '<%= hdfAssetType.ClientID %>').val());
        }
    </script>
       [System.Web.Script.Services.ScriptMethod()]
        [System.Web.Services.WebMethod]
        public static List<string> GetItem(string prefixText, int count, string contextKey)
        {
            
            var preUpperCase = prefixText.ToUpper();
            //var data = new Item().SelectAll();
            var data = new Item().SelectAllByAssetType();

            List<string> mList = data.Select(d => d.Name).ToList();

            var fList = (from d in mList
                         where d.ToUpper().Contains(preUpperCase)
                         select d).ToList();
            return fList;
        }

Comments

Popular posts from this blog

Easy Ui Jquery easyui-textbox change onChange event

Provision AWS EC2 Instance and RDS with Terraform, and Deploy Spring Boot App to EC2 Instance via GitHub Action Pipeline

npm install gets stuck at fetchMetadata