To answer this question, you need to understand how Web works in general.
You don't "change" anything in C#; this is not how things work. The whole operation of the server-side code is to respond to HTTP request and create an HTTP response. If this is HTML, your code creates
whole page. Naturally, after the callback you can generate HTML with different context. In other words, do it explicitly or make the value of the CSS
class
an ASP.NET expression (
<% … %>
). In addition to that, you can exchange arbitrary information via HTTP request/response using Ajax. Whole ASP.NET is all about this scheme.
After the page is rendered, the page content remains the same or can be modified on client side via JavaScript. You can write a static JavaScript or register client script in ASP.NET. This is how a script can modify a CSS classes of an element:
Element.className — Web APIs | MDN[
^],
Element.classList — Web APIs | MDN[
^].
If you do in on client side, the changes will be rendered immediately, no traffic will be used, and so on.
—SA