Telerik RadAutoCompleteBox with Custom Search Highlighting using Web API

Thread is closed for posting
3 posts, 0 answers
  1. 0A87D4E0-2DFD-4D96-811A-2FC7E78C9AFA
    0A87D4E0-2DFD-4D96-811A-2FC7E78C9AFA avatar
    40 posts
    Member since:
    Jul 2011

    Posted 12 Jul 2013 Link to this post

    Requirements

    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. 6F499E79-2505-4651-AFB9-B71AA9CB6C79
    6F499E79-2505-4651-AFB9-B71AA9CB6C79 avatar
    2 posts
    Member since:
    Jun 2010

    Posted 24 Sep 2013 Link to this post

    Otto,

    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. F89349FE-620D-4704-A4E7-93018A1D6EB7
    F89349FE-620D-4704-A4E7-93018A1D6EB7 avatar
    1192 posts
    Member since:
    May 2017

    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.
     

    Regards,
    Bozhidar
    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

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