---
title: "Check variable to set class value at runtime"  
description: "Check variable to set class value at runtime"  
author: "Anonymous User"  
published: 2014-08-25  
updated: 2014-08-25  
canonical: https://www.mindstick.com/forum/2119/check-variable-to-set-class-value-at-runtime  
category: "c#"  
tags: ["c#"]  
reading_time: 1 minute  

---

# Check variable to set class value at runtime

I've the following [code](https://yourviews.mindstick.com/view/85458/alan-turing-the-mastermind-behind-cracking-the-enigma-code-during-world-war-ii), it's supposed to [check if](https://www.mindstick.com/forum/12878/how-to-check-if-an-asp-dot-net-file-upload-control-has-a-file-in-jquery) a [variable](https://www.mindstick.com/articles/1807/objective-c-data-types-variables-object-creation) from a [DataList](https://www.mindstick.com/forum/1797/change-text-on-button-in-datalist-not-working), it's the same as a variable called mesActual,

```
      <li id="Li1" class='<%#
(Convert.ToBoolean(Convert.ToString(Eval("Month")) ==Convert.ToString(mesActual))) ? "activa" : "no-activa"
%>'>          
<asp:LinkButton ID="lnkbtn" runat="server"CommandName="Select" CommandArgument='<%#Eval("Month")%>'><%#Eval("Month")%></asp:LinkButton>           <div class="btn"><span><asp:Label ID="lbltot"
runat="server"></asp:Label></span></div>      </li>
```

On [page load](https://www.mindstick.com/articles/12909/how-to-open-first-time-popup-on-page-load-in-website), it seems to work, first item is selected and assigned the [class](https://www.mindstick.com/blog/165/generic-class-in-c-sharp) "activa", but when i [click](https://www.mindstick.com/articles/12423/social-login-magento-2-one-click-to-register-social) on the [button](https://www.mindstick.com/articles/63/how-to-add-button-in-datagridview-in-csharp-dot-net), it reloads the page, i can see my variable "mesActual" changed, but the class of the li doesn't change.

## Replies

### Reply by Sumit Kesarwani

Hi Goti, \

Try runat="server", <%# %> only fires on DataBind():

<li id="Li1" runat="server" class='<%# Convert.ToString(Eval("Month")) == Convert.ToString(mesActual) ? "activa" : "no-activa" %>'>


---

Original Source: https://www.mindstick.com/forum/2119/check-variable-to-set-class-value-at-runtime

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
