AspBucket offers ASP.NET, C#, VB, Jquery, CSS, Ajax, SQL tutorials. It is the best place for programmers to learn

Monday 8 February 2016

How to use jquery autocomplete in ASP.NET?

In this article I will discuss how to use Jquery autocomplete. Before use this add Jquery a reference in your project.

<script src=""></script>
<link rel="stylesheet" href="">
<script src=""></script>

Add Text box in Layout

<input type="text" id="txtid"/>

Jquery Auto Complete Code
                source: function (request, response) {
                        type: "POST",
                        url: "WCF Service Request URL",
                        data: JSON.stringify({inputstr:request.term}),
                        dataType: "json",
                        contentType: "application/json; charset=utf-8",
                        success: function (rType) {                          
                            response($.map(rType, function (item) {                                    
                                     return {
                                         label: item,   //manage label value in return json
                                         value: item
                        error: function (e) {//handel error }
                minLength: 3,
                autoFill: true,
                select: function (event, ui) {
                   //On select
                focus: function (event, ui) {
                    // On foucs
                change: function (event, ui) {
                    if (ui.item) {
                         //If Item found
                    } else {
                       //If Item not found
                search: function () { //on search
                open: function () { //On Open
Create Service method which return JSON data for autocomplete.

 WCF  Methods

1-Service Class
  #region--Get Company Auto Complete--
    public List<Company> GetAutoComplete(string inputstr)
        List<Company> CompanyData = GetCompany(inputstr));
        return CompanyData;

2-IService Class
[WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.Wrapped, ResponseFormat = WebMessageFormat.Json)]
List<Company> GetAutoComplete(string inputstr);
Hope you like this articles. Please give suggestion in below comments.


Post a Comment

  • Popular Posts
  • Comments