This is a migrated thread and some comments may be shown as answers.

SearchContext Client Events

10 Answers 166 Views
SearchBox
This is a migrated thread and some comments may be shown as answers.
John
Top achievements
Rank 1
John asked on 09 Sep 2013, 05:14 PM
I need to be able to detect, on the client, when the SearchContext selected item has changed. Is there a client event that fires when the user selects an item from the SearchContext dropdown?

10 Answers, 1 is accepted

Sort by
0
MasterChiefMasterChef
Top achievements
Rank 2
answered on 09 Sep 2013, 06:43 PM
Hi John,

For the SearchContext feature of the RadSearchBox, you can easily implement your own event to fire when the user changes their selection. There is a good example of data binding on the client side here in the documentation. This event will now return the selected row in the search context box. 

Good luck,
Chef Master Chief
0
John
Top achievements
Rank 1
answered on 09 Sep 2013, 07:44 PM
At this point, I can't get that to work. I'm binding the list of items, for the SearchContext object, on the server-side via an ADO DataTable (dt) object. I'm using:

With radSearchBox.SearchContext
        .DataSource = dt
        .DataTextField = "FieldDescription"
        .DataKeyField = "ID"
        .OnClientItemDataBound = "OnClientItemDataBound"
        .DataBind()
End With

The "OnClientItemDataBound" event in my client script file never fires. Other functions in the same client script file related to other Telerik controls fire correctly. I'm obviously missing something.
0
Bozhidar
Telerik team
answered on 12 Sep 2013, 09:58 AM
Hello John,

The OnClientItemDataBound event fires only if you are binding the SearchContext through WebService or OData - in other words on the client. Since you are using server-side binding, the event won't be triggered.
 

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.
0
John
Top achievements
Rank 1
answered on 15 Sep 2013, 09:16 PM
Ok - I'll change it to a web service.
0
John
Top achievements
Rank 1
answered on 18 Sep 2013, 09:16 PM
Successfully got the SearchContext items of a RadSearchBox to load from a WFC service (.svc). However, still unable to detect, on the client, when the user changes selections using the drop down. Any suggestions? The only event I see for the SearchContext object is "OnClientItemDataBound" and it's not getting called at all. If I enter an event defined in my JavaScript code, Visual Studio burps and states that the event is not a member of my page's class. I just need to know if it's possible to detect, on the client, when the user changes selections in the SearchContext dropdown control. I need to set some script var values when this happens.
0
Bozhidar
Telerik team
answered on 20 Sep 2013, 06:35 AM
Hi John,

In the current version of the SearchContext there aren't any predefined client events, however you can use some simple javascript to catch the click event of the item:
function pageLoad() {
    $telerik.$(".rsbListItem").on("click", function(e) {
        var item = Telerik.Web.UI.RadSearchBox._getTarget(e)._item;
    });
}

 

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.
0
John
Top achievements
Rank 1
answered on 24 Sep 2013, 03:30 PM
Hi Bozhidar,

I added the code you supplied to the pageLoad event. However, the "click" event for the list item(s) is not being attached/called. It has to be something with the control being reset? I've also tried adding the "click" function in the PageLoaded event (below) to no avail.

var prm = Sys.WebForms.PageRequestManager.getInstance();
prm.add_pageLoaded(PageLoaded);

function PageLoaded(sender, args) {
  $telerik.$(".rsbListItem").on("click", function (e) {
  e.preventDefault();
   var item = Telerik.Web.UI.RadSearchBox._getTarget(e)._item;
});

0
John
Top achievements
Rank 1
answered on 24 Sep 2013, 06:42 PM
It appears that the list items, possibly due to the fact that they are created on the fly and must wait for the return of the web service data (asynchronous call?), are not available, even after the page has been officially "loaded". I can witness this occurring using Chrome's DevTools debugger. jQuery's delegate "on" is not attaching to the list items. Is there anyway to detect, on the client, when the list items are finished being created? I just find it hard to believe that it's this difficult to simply determine when a user changes their selection in a control, regardless if it's dynamically created.
0
Accepted
Bozhidar
Telerik team
answered on 25 Sep 2013, 06:55 AM
Hello John,

Here's the modified code, which should work in all cases:
function pageLoad() {
    $telerik.$(".rsbPopup ").on("click", ".rsbListItem", function (e) {
        e.preventDefault();
 
        var itemData = Telerik.Web.UI.RadSearchBox._getTarget(e)._data;
        console.log(itemData.text);
    });
}

The itemData object contains all of the items properties, like text, value and all the properties that are specified by the DataKeyNames property.
 

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.
0
John
Top achievements
Rank 1
answered on 25 Sep 2013, 03:07 PM
Thank you so much. This solution appears to work. I did have to change it to:

var listItem = Telerik.Web.UI.RadSearchBox._getTarget(e)._item;
var listItemID = listItem._properties._data.key;
var listItemValue = listItem._properties._data.text;

to get the key and text of the item selected.
Tags
SearchBox
Asked by
John
Top achievements
Rank 1
Answers by
MasterChiefMasterChef
Top achievements
Rank 2
John
Top achievements
Rank 1
Bozhidar
Telerik team
Share this question
or