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

Setting a cssclass on a clicked item

1 Answer 21 Views
This is a migrated thread and some comments may be shown as answers.
Top achievements
Rank 2
sitefinitysteve asked on 18 May 2010, 03:09 PM
I'm my serverside code I'm setting a css class on a label item in the radrotator

So then OnClientItemClicked I clear the class from the item, but how the heck do I put that class onto the new item I clicked?


1 Answer, 1 is accepted

Sort by
Petio Petkov
Telerik team
answered on 20 May 2010, 03:05 PM
Hi Steve,

I created for you a simple example which adds a custom css class to the currently clicked element, and removes the css from the previously clicked element. Here it is the code:
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<head runat="server">
    <style type="text/css">
        .CustomStyle span
            color: Red !important;
    <form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
    <script type="text/javascript">
        var previousElement;
        function RotatorItemClick(rotator, args)
            var item = args.get_item();
            var index = item.get_index();
            var itemElement = item.get_element();
            Sys.UI.DomElement.addCssClass(itemElement, "CustomStyle");
            if (previousElement != null)
                Sys.UI.DomElement.removeCssClass(previousElement, "CustomStyle");
            previousElement = itemElement;
                <telerik:RadRotator ID="RadRotator1" runat="server" Width="80px" Height="20px"
                     ScrollDuration="500" FrameDuration="2000" ItemHeight="30" ItemWidth="30"
protected override void CreateChildControls()
       string[] months = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
       foreach(string month in months)
           RadRotatorItem rotatorItem = new RadRotatorItem();
           Label lbl = new Label();
           lbl.Text = month;

Let us know if you have any other questions.

Sincerely yours,
Petio Petkov
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Asked by
Top achievements
Rank 2
Answers by
Petio Petkov
Telerik team
Share this question