Setting a cssclass on a clicked item

2 posts, 0 answers
  1. Steve
    Steve avatar
    1851 posts
    Member since:
    Dec 2008

    Posted 18 May 2010 Link to this post

    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?

    Thanks,
    Steve
  2. Petio Petkov
    Admin
    Petio Petkov avatar
    825 posts

    Posted 20 May 2010 Link to this post

    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:
    ASPX:
    <%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
      
    <head runat="server">
        <title></title>
        <style type="text/css">
            .CustomStyle span
            {
                color: Red !important;
            }
        </style>
    </head>
    <body>
        <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;
      
            }
        </script>
        <div>
                    <telerik:RadRotator ID="RadRotator1" runat="server" Width="80px" Height="20px"
                         ScrollDuration="500" FrameDuration="2000" ItemHeight="30" ItemWidth="30"
                         OnClientItemClicked="RotatorItemClick">
                    </telerik:RadRotator>
        </div>
        </form>
    </body>
    </html>
    Codebehind:
    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();
               RadRotator1.Items.Add(rotatorItem);
               Label lbl = new Label();
               lbl.Text = month;
               rotatorItem.Controls.Add(lbl);
           }
       }

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top