AutoCompleteBox with Page Methods

2 posts, 0 answers
  1. Erick de
    Erick de avatar
    75 posts
    Member since:
    Feb 2010

    Posted 25 Oct 2013 Link to this post


    I have created a AutoCompleteBox similar as the following:
    <telerik:RadAutoCompleteBox ID="TEST" runat="server" AllowCustomEntry="false" DropDownPosition="Automatic" InputType="Token" RenderMode="Lightweight" Delimiter="," DataTextField="field_name" DataValueField="field_value">
    <WebServiceSettings Path="Default.aspx" Method="GetSet" />

    And in the code behind as the follows:
    Imports Telerik.Web.UI
    Imports System.Data
    Imports System.Web.Services
    Partial Class _Default
        Inherits System.Web.UI.Page
        <WebMethod()> _
        Public Function GetSet(context As RadAutoCompleteContext) As AutoCompleteBoxData
            Return Nothing
        End Function
    End Class

    After put some text in the AutoCompleteBox, he will alert 'the method 'GetSet' failed' all time. The breakpoint i had putted at the first rule of the webmethod don't fire. This did worked with other controls, but not with this control.

    Known issue or am i doing something wrong?
    I have checked the example in your documentation already.
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 28 Oct 2013 Link to this post

    Hi EM-Software,

    Please have a look into the following code I tried for your scenario which works fine at my end.

    <telerik:RadAutoCompleteBox ID="TEST" runat="server" AllowCustomEntry="false" DropDownPosition="Automatic"
        InputType="Token" RenderMode="Lightweight">
        <WebServiceSettings Path="Default.aspx" Method="GetSet" />

    VB : (Default.aspx.vb)
    <WebMethod> _
    Public Shared Function GetSet(context As Object) As AutoCompleteBoxData
        Dim searchString As String = DirectCast(context, Dictionary(Of String, Object))("Text").ToString()
        Dim selectCommand As New SqlCommand("SELECT * FROM [Products] WHERE ProductName LIKE @ProductName + '%'")
        selectCommand.Parameters.AddWithValue("ProductName", searchString.Replace("%", "[%]").Replace("_", "[_]"))
        selectCommand.Connection = New SqlConnection(ConfigurationManager.ConnectionStrings("NorthwindConnectionString").ConnectionString)
        Dim data As New DataTable()
        Dim adapter As New SqlDataAdapter(selectCommand)
        Dim result As New List(Of AutoCompleteBoxItemData)()
        For Each row As DataRow In data.Rows
            Dim childNode As New AutoCompleteBoxItemData()
            childNode.Text = row("ProductName").ToString()
            childNode.Value = row("ProductID").ToString()
        Dim res As New AutoCompleteBoxData()
        res.Items = result.ToArray()
        Return res
    End Function

Back to Top