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 8306781
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T18:23:52+00:00 2026-06-08T18:23:52+00:00

I cannot seem to figure out what is wrong with the code for the

  • 0

I cannot seem to figure out what is wrong with the code for the autocomplete search bar.

The only thing I can think of is that I referenced the wrong thing under URL

aspx Javascript

    $(document).ready(function() {
        SearchText();
    });
    function SearchText() {
        $(".ui-autocomplete").autocomplete({
            source: function(request, response) {
                $.ajax({
                    type: "POST",
                    contentType: "application/json; charset=utf-8",
                    url: "Admin_home.aspx/GetAutoCompleteData",
                    data: "{'Car':'" + document.getElementById('query').value + "'}",
                    dataType: "json",
                    success: function(data) {
                        response(data.d);
                    },
                    Error: function(results) {
                        alert("Error");
                    }
                });
            }
        });
    }

</script>`

aspx html code

I cant seem to type or paste the html here. It is just a
asp:Textbox ID=”query” class=”ui.autocomplete”

c# code

    [WebMethod]
    public static List<string> GetAutoCompleteData(string Car)
    {
        List<string> result = new List<string>();
        using (SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["CarsConnectionString"].ConnectionString))
        {
            using (SqlCommand cmd = new SqlCommand("select DISTINCT Car from T_Car where Car like '%'+ @SearchText +'%", con))
            {
                con.Open();
                cmd.Parameters.AddWithValue("@SearchText", Car);
                SqlDataReader dr = cmd.ExecuteReader();
                while (dr.Read())
                {
                    result.Add(dr["Car"].ToString());
                }
                return result;
            }
        }
    }

Would part of the html need to be wrapped in an AJAX update panel?

Also, I am having the search pull names from sql server 2005.

  • 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-08T18:23:54+00:00Added an answer on June 8, 2026 at 6:23 pm

    that is not how jQuery Autocomplete works,

    jQuery autocomplete automatically sends the text entered in the text box to the location you specify in a querystring “term” you access it in webmethod or handler like this

             string input = HttpContext.Current.Request.QueryString["term"];
    

    something like this

                  [WebMethod]
    public static List<string> GetAutoCompleteData(string Car)
    {
        string input = HttpContext.Current.Request.QueryString["term"];
        List<string> result = new List<string>();
        using (SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["CarsConnectionString"].ConnectionString))
        {
            using (SqlCommand cmd = new SqlCommand("select DISTINCT Car from T_Car where Car like '%'+ @SearchText +'%", con))
            {
                con.Open();
                cmd.Parameters.AddWithValue("@SearchText", input);
                SqlDataReader dr = cmd.ExecuteReader();
                while (dr.Read())
                {
                    result.Add(dr["Car"].ToString());
                }
                return result;
            }
        }
    }
    

    this goes in your .aspx page

        $(".ui-autocomplete").autocomplete({
            source: "Admin_home.aspx/GetAutoCompleteData",
            select: function (event, ui) { }
          });
    

    EDIT:

    I’ve never actually done this in web method , I usually use a handler .ashx , but this should work just as good.

    when you have all that changed , then run the site in debug mode, start to type in the textbox and fit f12 and watch the traffic that this is causing – if you type “abc” it should look like

    Admin_home.aspx/GetAutoCompleteData?term=abc

    then the response you might have to play with a little , by default .net is going to add “d : ….” to the response to client side , but you can watch it and adjust accordinly

    Another Edit:

             <asp:Textbox ID="query" class="ui.autocomplete">
    

    is not what you put in the jquery

              $(".ui-autocomplete").autocomplete({
    

    it should be

             <asp:Textbox ID="query" class="ui-autocomplete">
    

    Yet, Another Edit:

    This is missing a single quote

            using (SqlCommand cmd = new SqlCommand("select DISTINCT Car from T_Car where Car like '%'+ @SearchText +'%", con))
    

    replace with

             using (SqlCommand cmd = new SqlCommand("select DISTINCT Car from T_Car where Car like '%'+ @SearchText +'%' ", con))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I cannot figure out what is wrong with this fql.multiquery and cannot seem to
I cannot seem to figure out where I went wrong with this. favorite share
I cannot seem to figure out what is making this script go wrong... You
I cannot seem to figure out I am getting the following error in IE
Looking over the magento 1.5 schema I cannot seem to figure out how a
I cannot figure out this positioning problem in Firefox. It doesn't seem to follow
I can not seem to figure out how to count the number of seconds
...which I cannot seem to figure out, for whatever reason. I've tried cleaning my
I've looked and looked with the debugger and cannot seem to figure out why
I cannot seem to figure out how to do a Selection Alignment in the

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.