Setting the css-class for a menu-item based on the webpage url

2 posts, 0 answers
  1. Lars Melkevik
    Lars Melkevik avatar
    7 posts
    Member since:
    May 2005

    Posted 24 Nov 2011 Link to this post

    Is there a way I can set a css-class for a single menu-item based on the webpage url? (Maybe when the menu is generated?)
    The menu is generated from a database.

    Example:
    If url = www.domain.com/page.aspx?id=1 then I would like menuitem "Menuitem1" to have a red font color. And if url = www.domain.com/page.aspx?id=2 then I would like menuitem "Menuitem2" to have a red font color.

    Best regards,
    Lars
     
  2. Kate
    Admin
    Kate avatar
    1898 posts

    Posted 28 Nov 2011 Link to this post

    Hi Lars,

    Using the OnClientLoad event of the RadMenu control you can get the page url as described in the following forum posts:
    http://forums.digitalpoint.com/showthread.php?t=267256
    http://stackoverflow.com/questions/2426958/get-page-url-using-javascript
    http://stackoverflow.com/questions/1034621/get-current-url-with-javascript

    Then you can implement the logic according to your scenario - find the appropriate menu item and use the set_cssClass("nameOfCssClass") property in order to set a css class and alter the appearance of the item.

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