Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
I am trying to implement jquery autocomplete textbox in asp.net. But I am getting the error "Object doesn't support this property or method" though while coding I am getting 'autocomplete' function in intellisense. I have tried to use google api link as well in case my jquery files are not getting loaded correctly, but i am getting the same error. Following is my code:

JavaScript
<pre lang="HTML"><asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">  

   <script src="Scripts/jquery-1.11.2.js" type="text/javascript"></script>
    <script src="Scripts/jquery-ui.js" type="text/javascript"></script>        
    <link href="Styles/jquery-ui.css" rel="stylesheet" type="text/css" />
    <script language="JavaScript" type="text/JavaScript">
        $(document).ready(function () {

            $("[id*=txtPCTrx]").autocomplete({                    
                    source: function (request, response) {
                        $.ajax({
                            url: "PCAdd.aspx/GetAutoCompleteData",
                            type: "POST",
                            dataType: "json",
                            contentType: "application/json; charset=utf-8",
                            data: "{'txt':'" + $('[id*=txtPCTrx]').val() + "'}", //json to represent argument
                            dataFilter: function (data) { return data; },
                            success: function (data) {
                                response($.map(data.d, function (item) {
                                    return {
                                        label: item,
                                        value: item
                                    }
                                }))
                                //debugger;
                            },
                            error: function (result) {
                                alert("Error");
                            }
                        });
                    },
                    minLength: 1,
                    delay: 1000
                });
</script>


Apart from the above autocomplete function I have many other jquery functions which are working properly in the same page. Please help.
Posted

To accomplish this task I used WebService below is the code. IT's working fine for me. Check it out..

JavaScript
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js">
type = "text/javascript"></script> 
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js">
type = "text/javascript"></script> 
<link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css">
rel = "Stylesheet" type="text/css" /> 

<script type="text/javascript">
    $(document).ready(function () {
        $("#<%=txtSearch.ClientID %>").autocomplete({
            source: function (request, response) {
                $.ajax({
                    url: '<%=ResolveUrl("~/Service.asmx/GetAllEmployees") %>',
                    data: "{ 'prefix': '" + request.term + "'}",
                    dataType: "json",
                    type: "POST",
                    contentType: "application/json; charset=utf-8",
                    success: function (data) {
                        response($.map(data.d, function (item) {
                            return {
                                label: item.split('-')[0],
                                val: item.split('-')[1]
                            }
                        }))
                    },
                    error: function (response) {
                        alert(response.responseText);
                    },
                    failure: function (response) {
                        alert(response.responseText);
                    }
                });
            },
            select: function (e, i) {
                $("#<%=hfEmpUserId.ClientID %>").val(i.item.val);
            },
            minLength: 1
        });

    });
</script></link>
 
Share this answer
 
v3
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900