Telerik RadAutoCompleteBox with Custom Search Highlighting using Web API

Thread is closed for posting
3 posts, 0 answers
  1. Otto Neff
    Otto Neff avatar
    40 posts
    Member since:
    Jul 2011

    Posted 12 Jul 2013 Link to this post


    RadControls version Q2 2013
    .NET version 4.5
    Visual Studio version VS2012
    programming language C#
    browser support

    all browsers supported by RadControls

    Project Description.

    In this example it is demonstrated how to use the WebAPI to get highlighted search results with the Telerik RadAutoCompleteBox.

    A DataSet with System.Data.DataSetExtensions is used to apply LINQ Expressions for the filtering with AsEnumerable().

    It's very easy to change the data in the Web API Method to something like the new Entity Framework 6 with Async requests to improve client responsiveness and server scalability. Or even call other WebServices, XML Files on HD or wherever you get your data from.

    In this sample it is also added to the JSON Search POST Request some Text from a RadTextBox which is added to every search result.
    Instead of RadAutoCompleteContext I it is used dynamic in WebAPI Method combined with Newtonsoft Json.NET JsonConvert.DeserializeObject<dynamic>().

    The search results are formatted by ClientDropDownItemTemplate placing metadata in the variables #= Attributes.LOGO_URL # and #= Attributes.RESULT_HTML #.

    The selected Entry / Item is kept as Token with a GUID as Value and ShortText for the Token itself.

    For IgnoreCase Highlighting of the search terms in the results it is used Regular Expressions / Regex Method in ApiController.
  2. mga
    mga avatar
    2 posts
    Member since:
    Jun 2010

    Posted 24 Sep 2013 Link to this post


    This works great until a results are shown and then a postback occurs.  At that point this error is shown: 

    A potentially dangerous Request.Form value was detected from the client (radAutoComplete_ClientState="...LT_HTML":"<b><b style='color:r...").

  3. Bozhidar
    Bozhidar avatar
    1192 posts

    Posted 27 Sep 2013 Link to this post

    Hi Milton,

    This happens because in the project HTML  is put directly as a value for one of the AutoCompleteBoxEntry's attributes, and upon postback this value is being sent to the server. In this scenario we highly advice you put all your html inside the client template of the AutoCompleteBox, and only store actual string values as attributes of the control.

    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

This Code Library is part of the product documentation and subject to the respective product license agreement.