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

Setting CSS styles from code behind

1 Answer 637 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Developer
Top achievements
Rank 1
Developer asked on 23 Sep 2016, 10:33 AM

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.

1 Answer, 1 is accepted

Sort by
0
Ivan Danchev
Telerik team
answered on 27 Sep 2016, 10:19 AM
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.
Tags
General Discussions
Asked by
Developer
Top achievements
Rank 1
Answers by
Ivan Danchev
Telerik team
Share this question
or