I'm adapting the autocomplete example posted at
http://munich.schwarz-interactive.de/autocomplete.aspx but using only 1
textbox as that's all that I require.

I keep gettting a javascript "AutoComplete is undefined" error when I
enter any text into the textbox. Can someone help me out please?

AUTOCOMPLETE.ASPX
==========================================================

<%@ Page Language="VB" AutoEventWireup="false"
CodeFile="autocomplete.aspx.vb" Inherits="_Default"
EnableViewState="false" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";>

<html xmlns="http://www.w3.org/1999/xhtml"; >
<head runat="server">
    <title>Autocomplete Test using Ajax.NET Pro</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <p>Staff Member: <input type="text" id="searchStaffMember" /></p>
    </div>
    <script type="text/javascript"
src="ajaxpro/prototype.ashx"></script>
    <script type="text/javascript" src="ajaxpro/core.ashx"></script>
    <script type="text/javascript" src="ajaxpro/ms.ashx"></script>
    <script type="text/javascript"
src="ajaxpro/converter.ashx"></script>
    <script type="text/javascript"
src="assets/scripts/autocomplete.js"></script>
    <script type="text/javascript">
        function init() {
          var x = new MS.Web.AutoCompleteDataTable("searchStaffMember",
10);

          x.getDisplay = function(item) {
            return (item != null ? item.StaffName : "");
          }
          x.getValue = function(item) {
            return (item != null ?
item.StaffName.toString().trimRight() : "");
          }
          x.getData = function() {
            AutoComplete.Search(this.ele.value, this.count,
this.callback.bind(this));
          }
        }
        addEvent(window, 'load', init);
    </script>
    </form>
</body>
</html>

AUTOCOMPLETE.ASPX.VB
==========================================================

Imports System.Data
Imports System.Data.SqlClient

<AjaxPro.AjaxNamespace("AutoComplete")> _
    Partial Public Class _Default
    Inherits System.Web.UI.Page
    <AjaxPro.AjaxMethod()> _
    Public Function Search(ByVal searchString As String, ByVal count As
Integer) As DataTable
        Dim dt As DataTable = New DataTable()

        dt.Columns.Add("StaffID", Type.GetType("integer"))
        dt.Columns.Add("StaffName", Type.GetType("string"))

        Dim conn As SqlConnection = New
SqlConnection(System.Configuration.ConfigurationManager.AppSettings("hrdb"))

        Dim cmd As SqlCommand = New SqlCommand("SELECT Staff_Id,
(RTRIM(Surname) + ', ' + RTRIM(Known_as)) As Name FROM Staff WHERE
(RTRIM(Surname) + ', ' + RTRIM(Known_as)) LIKE @Name ORDER BY Surname,
Known_as", conn)
        cmd.Parameters.AddWithValue("@Name", searchString & "%")

        Try
            conn.Open()

            Try
                Dim dr As SqlDataReader = cmd.ExecuteReader
                Dim row As DataRow

                While dr.Read()
                    If dr(0) Is DBNull.Value Or dr(1) Is DBNull.Value
Then
                        Continue While
                    End If

                    row = dt.NewRow()

                    row("StaffID") = dr(0)
                    row("StaffName") = dr(1)

                    dt.Rows.Add(row)
                End While
            Finally
                conn.Close()
            End Try
        Catch ex As Exception
            Throw ex
        End Try

        Return dt
    End Function

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As
EventArgs)
        ' Register Ajax.NET methods from this class
        AjaxPro.Utility.RegisterTypeForAjax(GetType(_Default))
    End Sub

End Class


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Ajax.NET Professional" group.

To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]

For more options, visit this group at http://groups.google.com/group/ajaxpro

The latest downloads of Ajax.NET Professional can be found at 
http://www.ajaxpro.info
-~----------~----~----~----~------~----~------~--~---

Reply via email to