8 Answers, 1 is accepted
0
Accepted
Hi Stephen Brooker,
You can use the following client side code to handle the click event of the item with index zero:
Best wishes,
Genady Sergeev
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
You can use the following client side code to handle the click event of the item with index zero:
<script type="text/javascript"> |
$telerik.$(document).ready(function() { |
var listBox = $find("RadListBox1"); |
$telerik.$(".rlbItem:first", listBox.get_element()) |
.click(function() { |
alert("This is event handler for click on the first item") |
}); |
}); |
</script> |
Best wishes,
Genady Sergeev
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0

Stephen
Top achievements
Rank 1
answered on 25 Aug 2009, 04:53 PM
I am wanting to use the client to raise a simulated click event against the ListBox control. In other words I want the client to "click" the ListBox control instead of physically using the mouse to click it. Thanks
0
Accepted

Shinu
Top achievements
Rank 2
answered on 26 Aug 2009, 06:40 AM
Hi Stephen Booker,
Give a try with following client side code for selecting first item from client side and see whether it is working as you expected.
JavaScript:
Checkout following links for important methods of the client-side RadListBox/RadListBoxItem object:
RadListBox client API
RadListBoxItem client API
-Shinu.
Give a try with following client side code for selecting first item from client side and see whether it is working as you expected.
JavaScript:
<script type="text/javascript"> |
function clickFirstItem() |
{ |
var list = $find("<%= RadListBox1.ClientID %>"); |
var item = list.getItem(0); // get the first item |
item.select(); // Select the item |
} |
</script> |
Checkout following links for important methods of the client-side RadListBox/RadListBoxItem object:
RadListBox client API
RadListBoxItem client API
-Shinu.
0

Stephen
Top achievements
Rank 1
answered on 26 Aug 2009, 12:06 PM
This worked fine. Thanks for the help.
0

Jerry
Top achievements
Rank 1
answered on 06 Sep 2012, 11:35 PM
In response to the first Answer by Genady Sergeev
This works good, and I'm able to have it fire for all items in a list box by removing :first.
Is there a way to attach this event to every listbox on a page without replicating the function and to pass as an argument which listbox was clicked?
thanks
This works good, and I'm able to have it fire for all items in a list box by removing :first.
Is there a way to attach this event to every listbox on a page without replicating the function and to pass as an argument which listbox was clicked?
thanks
0
Hi Jerry,
Hope this will be helpful.
All the best,
Plamen
the Telerik team
You can add this functionality in the OnClientLoad function of each RadListBox as in the code below:
function
OnClientLoadHandler(sender, args) {
var
listBox = sender;
$telerik.$(
".rlbItem:first"
, listBox.get_element())
.click(
function
() {
alert(
"This is event handler for click on the first item"
)
});
}
<
telerik:RadListBox
runat
=
"server"
ID
=
"RadListBox1"
OnClientLoad
=
"OnClientLoadHandler"
>
<
Items
>
<
telerik:RadListBoxItem
Text
=
"aaa"
/>
</
Items
>
</
telerik:RadListBox
>
<
telerik:RadListBox
runat
=
"server"
ID
=
"RadListBox2"
OnClientLoad
=
"OnClientLoadHandler"
>
<
Items
>
<
telerik:RadListBoxItem
Text
=
"aaa"
/>
</
Items
>
</
telerik:RadListBox
>
Hope this will be helpful.
All the best,
Plamen
the Telerik team
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 their blog feed now.
0

Jerry
Top achievements
Rank 1
answered on 04 Oct 2012, 08:02 PM
This is working well, thanks.
I am adding items to the listbox client-side, but am unable to get this event attached to the new items. I've tried creating a new item and cloning an existing item (that the click event works for). And I've tried add and insert.
Is there a way to add an item client-side with the event attached to it?
, Jerry
I am adding items to the listbox client-side, but am unable to get this event attached to the new items. I've tried creating a new item and cloning an existing item (that the click event works for). And I've tried add and insert.
Is there a way to add an item client-side with the event attached to it?
, Jerry
0
Hi Jerry,
Hope this will be helpful.
Kind regards,
Plamen
the Telerik team
You can use jQuery and the following code in order to add click event to the new items:
function
OnClientClicked(sender, args) {
var
listBox = $find(
'<%= RadListBox2.ClientID %>'
);
var
item =
new
Telerik.Web.UI.RadListBoxItem();
item.set_text(
"Item Text"
);
listBox.get_items().add(item);
$telerik.$(item.get_element()).click(
function
() {
alert(
"This is event handler for click on the NEW item"
)
});
}
Hope this will be helpful.
Kind regards,
Plamen
the Telerik team
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 their blog feed now.