Dear Team,
I want to implement an Autocomplete / Autosearch textbox in normal web page.
I have tried all the methods, but I get only 1 error -
0x800a01b6 - JavaScript runtime error: Object doesn't support property or method 'autocomplete'
My Code -
- <%@ Page Language="VB" AutoEventWireup="false" CodeFile=" frmManageAdmission.aspx.vb" Inherits=" frmManageAdmission" %>
- <!DOCTYPE html PUBLIC>
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head runat="server">
- <title> </title>
- </head>
- <body>
- <form id="Form1" method="post" runat="server">
- <link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/themes/base/jquery-ui.css" type="text/css" media="all" />
- <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.js" type="text/javascript"></script>
- <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/jquery-ui.min.js" type="text/javascript"></script>
- <script type="text/javascript">
- $(document).ready(function () {
- $("#<%=txtFirstName.ClientID%>").autocomplete({
- source: function (request, response) {
- $.ajax({
- url: '<%=ResolveUrl("~/frmManageAdmission.aspx/GetFirstNames") %>',
- data: "{ 'prefixText': '" + 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('-x-')[1],
- val: item.split('-x-')[0]
- }
- }))
- },
- error: function (response) {
- alert(response.responseText);
- },
- failure: function (response) {
- alert(response.responseText);
- }
- });
- },
- select: function (e, i) {
- $("#<%=hdnfldFirstName.ClientID%>").val(i.item.val);
- },
- minLength: 2
- });
- });
- </script>
- <table cellspacing="0" cellpadding="6" width="100%" border="0">
- <tr>
- <td>First Name</td>
- <td>
- <asp:TextBox ID="txtFirstName" runat="server" MaxLength="100" OnTextChanged="txtFirstName_TextChanged" AutoPostBack="true" CssClass="autosuggest"></asp:TextBox>
- <asp:HiddenField ID="hdnfldFirstName" runat="server" />
- </td>
- </tr>
- </table>
- <br>
- </form>
- </body>
- </html>
Ccs/vb code -
- #Region "ConnectionString"
- <WebMethod()> _
- Public Shared Function ConnectionString() As String
- Try
- Return ConfigurationManager.ConnectionStrings("DBConnectionString").ConnectionString.Trim
- Catch err As Exception
- err.Message.ToString()
- Return Nothing
- End Try
- End Function
- #End Region
- #Region "CheckIfConnectionIsOpen"
- <WebMethod()> _
- Public Function IsOpen() As Boolean
- Try
- SqlConnection.ClearAllPools()
- con = New SqlConnection
- If con.ConnectionString Is String.Empty Then
- con.ConnectionString = ConnectionString()
- End If
- If con.State = ConnectionState.Closed Then
- con.Open()
- Return True
- Else
- Return True
- End If
- Catch err As Exception
- err.Message.ToString()
- Return False
- End Try
- End Function
- #End Region
- #Region "GetFirstNames"
-
- <WebMethod()> _
- Public Function GetFirstNames(ByVal prefixText As String) As String()
- Try
- If IsOpen() = True Then
- Dim s As String = HttpContext.Current.Session("AutoSuggestFirstName").ToString
-
- Dim FirstNames = New List(Of String)
- cmd = New SqlCommand
- cmd.Connection = con
- cmd.CommandText = "SP_AutoSuggestFirstName"
- cmd.CommandType = CommandType.StoredProcedure
- cmd.Parameters.AddWithValue("@PreficxFirstName", prefixText)
- Using sdr As SqlDataReader = cmd.ExecuteReader
- While sdr.Read
- FirstNames.Add(String.Format("{0}-{1}", sdr("Candidate_FName"), sdr("am_id")))
- End While
- End Using
- Return FirstNames.ToArray
- Else
- Return Nothing
- End If
- Catch err As Exception
- err.Message.ToString()
- Return Nothing
- End Try
- End Function
- #End Region
Please let me know - where I am going wrong..