function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
sampath kumar 3sampath kumar 3 

can we assign css dynamically by using apex

Is it possible to controll CSS from Apex controller 
Ex:  I'm fetching data by using SOQL query and if  data is fetched from SOQL then only need to perform CSS .So I would like to write a condition in apex but how to assign css from apex I have  external css file contians list of css classes how can I assign those classes based on the condition in apex without using javascript . Please let me know
Sagar Wahal 1Sagar Wahal 1
Hi Sampath,

One possible way to do this would be to create a boolean variable in your controller for example - 'flag'. Set this field to true in your controller when you want to apply css, else set it to false

In your VF page use this 'flag' variable as stated below:
 
<apex:commandButton id="doActionButton" styleClass="{!IF(flag,'cssClassName','')}" action="{!doAction}"  value="Save" />
Let me know if you face any issue.

Regards,
Sagar Wahal
sampath kumar 3sampath kumar 3
Thanks Sagar but not in this way would like to perform condition in apex itself will it possible
Sagar Wahal 1Sagar Wahal 1
Hi Sampath,

Instead of passing a boolean variable, why dont you pass the name of your css class itself.

For example - Create a String cssClassName in your controller. Set the value of the cssClassName according to the condition you want in your controller.

Now in your VF page use it as follows:
<apex:commandButton id="doActionButton" styleClass="{!cssClassName}" action="{!doAction}"  value="Save" />

Hope, this solves your query. Let me know if you face any issues.

Regards,
Sagar