1

Please Help!

I am trying to use a Web Service (ASMX) file. When i view this and query it the page returns exactly what I want. So that page seems to be fine.

The issue is I'm trying to add an auto-complete to a textbox in my ASP.NET application but it doesn't seem to be doing anything! I've included all the relevant JQuery files (jquery-ui.js, jquery-ui-css, query-1-11.2.min.js) in my Site.master file.

Within my page i've included the Javascript to do the autocomplete.

Can anyone point my in the right direction? I'm still using IE8...

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
<script type="text/javascript">
    $(document).ready(function () {
        $('#txtAutoFill').autocomplete({
            minLength: 2,
            source: function (request, response) {
                $.ajax({
                    url: 'UserList.asmx/GetAutoCompleteData',
                    method: 'post',
                    contentType: 'application/json;charset=utf-8',
                    //data: JSON.stringify({ username: request.username }),
                    data: request.username,
                    dataType: "json",
                    success: function (data) {
                        response(data.d);
                    },
                    error: function (XMLHttpRequest, textStatus, errorThrown) {
                        alert(textStatus);
                    }
                });
            }
        });
    });
</script>

<asp:Content ID="Content2" ContentPlaceHolderID="mainContentPH" runat="server">
    <h1 id="h01"></h1>
    <asp:TextBox ID="txtAutoFill" runat="server" CssClass="form-control"></asp:TextBox>

</asp:Content>
Gareth
  • 512
  • 1
  • 4
  • 15

2 Answers2

0

One thing to check. Even though your text box id is "txtAutoFill" at the server side, it may include the container id when the actual page is generated (i.e. Content2_txtAutoFill). If that is the case, view page source in the browser and change your id within your javascript to match that. Also please see Understanding and implementing jQuery autocomplete with AJAX source and appendTo

Community
  • 1
  • 1
user890255
  • 458
  • 5
  • 9
0

Add ClientIDMode="Static" to your TextBox control

<asp:TextBox ClientIDMode="Static" ID="txtAutoFill" runat="server" CssClass="form-control"></asp:TextBox>
rai
  • 68
  • 3