Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8426791
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T04:37:27+00:00 2026-06-10T04:37:27+00:00

I have a textbox hooked up to jQuery UI Autocomplete widget. The source for

  • 0

I have a textbox hooked up to jQuery UI Autocomplete widget. The source for the autocomplete is a WebMethod returning a list of ‘Person’ objects. The user will start typing a persons name and then makes their selection from the autocomplete list. I then want several other textboxes to populate with values (company, phone, email, etc) based on the item selected from autocomplete list. These other values are contained in the returned ‘Person’ object.

My WebMethod is successfully populating the list of objects but the autocomplete list does not appear when the user enters text. I’m not sure how to tell if the list of objects is actually being properly passed back out to the jQuery Autocomplete.

So this is a 2 part question:

  1. Why is the autocomplete list not populating?
  2. Is my code to populate the secondary textboxes correct?

Please note that I have looked at all the other ‘could be percieved to be duplicate’ questions but none of them addressed this particular scenario.

My Person class:

public class Person
{
    //New properties -------------
    public string label {get; set;}
    public string value {get; set;}
    // ----------------------------
    public string Name {get; set;}
    public string Company {get; set;}
    public string Phone {get; set;}
    public string Mobile {get; set;}
    public string Email {get; set;}
    public string Fax {get; set;}
}

The HTML/Javascript:

<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
    <link href="Scripts/themes/ui-lightness/jquery.ui.all.css" rel="stylesheet" type="text/css" />
    <script src="js/jquery-1.5.1.min.js" type="text/javascript"></script>
    <script src="js/jquery-ui-1.8.12.custom.min.js" type="text/javascript"></script>
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
    <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="True">
    </asp:ScriptManager>
    <div>
        <asp:TextBox ID="txtName" runat="server"></asp:TextBox>
    </div>
    <div>
        <asp:TextBox ID="txtCompany" runat="server" ></asp:TextBox>
        <asp:TextBox ID="txtPhone" runat="server" ></asp:TextBox>
        <asp:TextBox ID="txtMobile" runat="server" ></asp:TextBox>
        <asp:TextBox ID="txtEmail" runat="server" ></asp:TextBox>
        <asp:TextBox ID="txtFax" runat="server" ></asp:TextBox>
    </div>
    <script type="text/javascript">
        PageMethods.SearchContacts(function (results) {
            $("#txtName").autocomplete({
                source: results,
                select: function (event, ui) {
                    $('#txtCompany').val(ui.item.company);
                    $('#txtPhone').val(ui.item.phone);
                    $('#txtMobile').val(ui.item.mobile);
                    $('#txtEmail').val(ui.item.mobile);
                    $('#txtFax').val(ui.item.mobile);
               }
            });
        });
    </script>
</asp:Content>

The WebMethod returning list of Person objects:

[System.Web.Script.Services.ScriptMethod()]
[System.Web.Services.WebMethod]
public static List<Person> SearchContacts()
{
    try
    {
        using (SqlConnection conn = new SqlConnection())
        {
            conn.ConnectionString = ConfigurationManager.ConnectionStrings["ConnStr"].ConnectionString;
            using (SqlCommand cmd = new SqlCommand())
            {
                cmd.CommandText = "SELECT Name, Company, PhoneOffice, PhoneMobile, Email, Fax FROM Contacts";
                cmd.Connection = conn;
                conn.Open();
                List<Person> contacts = new List<Person>();
                using (SqlDataReader sdr = cmd.ExecuteReader())
                {
                    while (sdr.Read())
                    {
                        Person person = new Person();
                        //New properties --------------------
                        person.label = sdr["Name"].ToString();
                        person.value = sdr["Name"].ToString();
                        // ----------------------------------
                        person.Name = sdr["Name"].ToString();
                        person.Company = sdr["Company"].ToString();
                        person.Phone = sdr["PhoneOffice"].ToString();
                        person.Mobile = sdr["PhoneMobile"].ToString();
                        person.Email = sdr["Email"].ToString();
                        person.Fax = sdr["Fax"].ToString();
                        contacts.Add(person);
                    }
                }
                conn.Close();
                return contacts;
            }
        }
    }
    catch (Exception ex)
    {
        throw new Exception(ex.Message);
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T04:37:28+00:00Added an answer on June 10, 2026 at 4:37 am

    Figured it out with some help from Andrew

    First thing was to add ‘label‘ and ‘value‘ properties to my Person class. The jQuery Autocomplete widget expects the following data format for an array of objects:

    [ { label: "Choice1", value: "value1" }, ... ]
    

    Second thing was that I needed to set the ClientIDMode to ‘Static’ on all the textboxes.

    <asp:TextBox ID="txtName" runat="server" ClientIDMode="Static"></asp:TextBox>
    

    Third thing was that referencing the object properties in javascript is case sensitive.

    $('#txtCompany').val(ui.item.Company);  //Needed uppercase 'C' on Company to match class definition
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an asp textbox that I have hooked up to a jQuery calendar
Desktop window application. I have textbox in which user give values in numbers. what
I have a textbox user control and when I double click, it adds the
I am using jquery on asp.net mvc. I have textbox on page and I
I have textbox that I want to run some jquery when the textbox loses
Can you tell me when will use CustomValidator. For eg I have Textbox that
I am creating intellisense as Java's intellisense at C#.I have TextBox which user can
I have a textbox where i want to read user-input mathematical functions( ex: Math.Sqrt(x)
I have validation hooked up to a model that is bound to the TextBox
I am creating a user form. In this I have textbox and a lot

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.