RadSearchBox and [WebMethod] Issues

4 posts, 0 answers
  1. Merritt
    Merritt avatar
    28 posts
    Member since:
    Mar 2011

    Posted 21 Apr 2015 Link to this post

    <%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="TelerikWebFormsTestBed._Default" %>
    <%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI, Version=2015.1.225.40, Culture=neutral, PublicKeyToken=121fae78165ba3d4" %>
     
    <asp:Content ID="BodyContent" ContentPlaceHolderID="MainContent" runat="server">
        <telerik:RadAjaxPanel runat="server" ID="RadAjaxPanel1">
             <h2>Page methods</h2>
            <telerik:RadSearchBox ID="RadSearchBox2" runat="server"
                                  EmptyMessage="Search Products" Width="300">
                <WebServiceSettings Path="default" Method="GetResults"/>
            </telerik:RadSearchBox>
            <p>
                <asp:Label runat="server" ID="Label1" />
            </p>
        </telerik:RadAjaxPanel>
    </asp:Content>

     

    and

     

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web.Script.Services;
    using System.Web.Services;
    using System.Web.UI;
    using Telerik.Web.UI;
     
    namespace TelerikWebFormsTestBed
    {
        public partial class _Default : Page
        {
            private static readonly List<String> MyData = new List<string> {"a", "b", "c"};
     
            protected void Page_Load(object sender, EventArgs e)
            {
            }
     
            protected void RadSearchBox2_Search(object sender, SearchBoxEventArgs e)
            {
                Label1.Text = "Text: " + e.Text;
            }
     
            [WebMethod]
            public static SearchBoxData GetResults(SearchBoxContext context)
            {
                var results = MyData.Where(x => x.StartsWith(context.Text));
                var sbids = new List<SearchBoxItemData>();
                foreach (var result in results)
                {
                    var itemData = new SearchBoxItemData();
                    itemData.Text = itemData.Value = result;
                    sbids.Add(itemData);
                }
                var sbd = new SearchBoxData {Items = sbids.ToArray()};
                return sbd;
            }
        }
    }

     GetResults is never invoked. The Page_Load is every time I type something, but not the actual method... 

     

     

  2. Merritt
    Merritt avatar
    28 posts
    Member since:
    Mar 2011

    Posted 21 Apr 2015 Link to this post

    It seems to be returning the whole page...
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Bozhidar
    Admin
    Bozhidar avatar
    1103 posts

    Posted 24 Apr 2015 Link to this post

    Hi,

    You have to set "default.aspx" as the Path parameter of the WebServiceSettings, instead of "default". I've also attached a working sample to demonstrate the working control.

    Regards,
    Bozhidar
    Telerik
     

    See What's Next in App Development. Register for TelerikNEXT.

     
  5. Merritt
    Merritt avatar
    28 posts
    Member since:
    Mar 2011

    Posted 24 Apr 2015 Link to this post

    I tried that but was getting an "Authentication Failed" message. Changing the RouteConfig RedirectMode seemed to fix the problem:

     

    public static class RouteConfig
    {
        public static void RegisterRoutes(RouteCollection routes)
        {
            var settings = new FriendlyUrlSettings();
            settings.AutoRedirectMode = RedirectMode.Off;
            routes.EnableFriendlyUrls(settings);
        }
    }

Back to Top