Setting CSS styles from code behind

2 posts, 0 answers
  1. Developer
    Developer avatar
    38 posts
    Member since:
    Apr 2014

    Posted 23 Sep Link to this post

    Hi,
    I am using a rad org chart.  Basically I want to apply certain CSS styles based on a condition.
    I have figured out how to just override a css styles:

    .rocToolbar_Metro .rocToolbarButton {   background-color: #32b330 !important;}


    But I can’t figure out how to do this conditionally via the code behind, so saying if condition == 1 then apply this:

    .rocToolbar_Metro .rocToolbarButton {    background-color: #32b330 !important;}


    Else apply this:

    .rocToolbar_Metro .rocToolbarButton {    background-color: #25a0da !important;}



    I am planning to do this within the NodeDataBound event.  Any suggestions appreciated.
    Thanks.

  2. Ivan Danchev
    Admin
    Ivan Danchev avatar
    835 posts

    Posted 27 Sep Link to this post

    Hello,

    If you want to apply styles to the control with class ".rocToolbarButton " depending on a condition on the server you can set a custom class through the control's CssClass property. So let's say you want to set an asp:Button's background-color:
    if (your condition)
    {
         Button1.CssClass = "MyCustomClass1";
    }
    else
    {
        Button1.CssClass = "MyCustomClass2";
    }

    you will have two rules that use these classes as selectors:
    .MyCustomClass1 {
        background-color: #32b330 !important;
    }
     
    .MyCustomClass2 {
        background-color: #25a0da !important;
    }


    Regards,
    Ivan Danchev
    Telerik by Progress
    Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top