Error binding autocomplete to web method

4 posts, 0 answers
  1. Oren
    Oren avatar
    21 posts
    Member since:
    Mar 2012

    Posted 09 Jan 2014 Link to this post

    Hello,
    I tried to build a small test page that has a autocompletebox bind to a web method in the code behind of the page.
    I copied the example from the autocompletedemo page, but I got this error : "The server method 'GetCompanyNames' failed."
    There is a snippet of my code:

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
     
    <!DOCTYPE html>
     
    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
            <telerik:RadScriptManager runat="server"></telerik:RadScriptManager>
            <telerik:RadAjaxPanel runat="server" ID="RadAjaxPanel1">
                <div>
                    <fieldset style="width: 400px">
                        <legend>Web service binding</legend>
                        <label for="RadAutoCompleteBox2">
                            Company Names:</label>
                        <telerik:RadAutoCompleteBox runat="server" ID="RadAutoCompleteBox2" Width="250" DropDownHeight="150"
                            DropDownWidth="250">
                            <WebServiceSettings Path="Defualt.aspx" Method="GetCompanyNames" />
                        </telerik:RadAutoCompleteBox>
                        <p>
                            <asp:Label runat="server" ID="Label2" />
                        </p>
                    </fieldset>
                </div>
            </telerik:RadAjaxPanel>
        </form>
    </body>
    </html>


    Code behind:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.Services;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using Telerik.Web.UI;
     
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
     
        }
        [WebMethod]
        public AutoCompleteBoxData GetCompanyNames(object context)
        {
            string searchString = ((Dictionary<string, object>)context)["Text"].ToString();
            List<AutoCompleteBoxItemData> result = new List<AutoCompleteBoxItemData>();
            AutoCompleteBoxItemData childNode = new AutoCompleteBoxItemData();
            childNode.Text = "aaaa";
            childNode.Value = "aaaa";
            result.Add(childNode);
     
            AutoCompleteBoxData res = new AutoCompleteBoxData();
            res.Items = result.ToArray();
     
            return res;
        }
    }



    Thank you for your help,
    Kind regards,
    Oren Yardeni.
  2. Nencho
    Admin
    Nencho avatar
    1457 posts

    Posted 14 Jan 2014 Link to this post

    Hello Oren,

    Please make sure that you had correctly referenced the aspx page name, where the WebMethod is implemented. As I can see, you are referring to <WebServiceSettings Path="Defualt.aspx", while the page is _Default.aspx.

    Regards,
    Nencho
    Telerik
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Oren
    Oren avatar
    21 posts
    Member since:
    Mar 2012

    Posted 14 Jan 2014 Link to this post

    Hello,
    Thank you for your reply , I fixed this and check the method name is correct and the path is correct but still I get the same error.
    Kind regards,
    Oren
  5. Nencho
    Admin
    Nencho avatar
    1457 posts

    Posted 17 Jan 2014 Link to this post

    Hello Oren,

    The Access Modifier of the WebMethod should be public static, in order to call the method correctly. I am sending you a sample project, demonstrating the entire correct implementation.

    Note : dll files are removed from the attachment.

    Regards,
    Nencho
    Telerik
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
Back to Top