This is a migrated thread and some comments may be shown as answers.

AutoCompleteBox with Page Methods

1 Answer 84 Views
This is a migrated thread and some comments may be shown as answers.
Top achievements
Rank 2
Erick asked on 25 Oct 2013, 09:30 AM

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.

1 Answer, 1 is accepted

Sort by
Top achievements
Rank 2
answered on 28 Oct 2013, 12:54 PM
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

Asked by
Top achievements
Rank 2
Answers by
Top achievements
Rank 2
Share this question