New to Telerik UI for ASP.NET AJAX? Start a free 30-day trial
OnClientItemSelected
The OnClientItemSelected is a Client-Side event that is triggered when an item from the SearchBox dropdown (SearchContext) is clicked.
The event handler receives two parameters:
-
The instance of (
Telerik.Web.UI.SearchContext
) firing the event, the SearchContext object. -
The event arguments that contains the following methods:
(Telerik.Web.UI.SearchContextItem)
get_item() - returns the SearchContextItem object.(bool)
get_isDefaultItem() - returnstrue
if the Default ("All") item was selected(string)
get_text() - returns the selected SearchContext Item's Text(string/int)
get_key() - returns the selected SearchContext Item's Key (commonly known as the value)
ASP.NET
<telerik:RadSearchBox RenderMode="Lightweight" runat="server" ID="RadSearchBox1"
DataTextField="Desc" DataValueField="Id">
<SearchContext DataTextField="Desc" DataKeyField="Id" OnClientItemSelected="OnClientItemSelected">
</SearchContext>
</telerik:RadSearchBox>
JavaScript
function OnClientItemSelected(sender, args) {
var searchContext = sender; // Telerik.Web.UI.SearchContext
var searchContextItem = args.get_item(); // Telerik.Web.UI.SearchContextItem
var isDefaultItem = args.get_isDefaultItem(); // bool
var text = args.get_text(); // SearchContext Item's Text
var key = args.get_key(); // SearchContext Item's Key (value)
}