---
title: "How remove css class in code behind .net 2.0"  
description: "How remove css class in code behind .net 2.0"  
author: "Anonymous User"  
published: 2014-01-28  
updated: 2014-01-29  
canonical: https://www.mindstick.com/forum/1898/how-remove-css-class-in-code-behind-dot-net-2-0  
category: "c#"  
tags: ["c#"]  
reading_time: 1 minute  

---

# How remove css class in code behind .net 2.0

My [div contains](https://www.mindstick.com/forum/12847/how-to-add-a-div-contains-asp-label-from-code-behind-in-asp-dot-net) 4 [css](https://www.mindstick.com/forum/514/background-gradient-ie7-css-problem) [class](https://www.mindstick.com/blog/165/generic-class-in-c-sharp) I want to [delete](https://www.mindstick.com/forum/33620/how-to-delete-record-from-list-in-mvc-using-ajax) one from them for adding, I do this:

MyDivId.Attributes["class"] += " addedClass";

in newest [framework](https://www.mindstick.com/forum/34615/software-framework-vs-library) they can be done like this:

MyDivId.[CssClass](https://www.mindstick.com/forum/12787/how-to-get-access-to-cssclass-property-for-server-element-isn-t-webcontrol-in-asp-dot-net).Replace("addedClass", "");

but in .net [2.0](https://answers.mindstick.com/qa/49733/what-is-web-version-web-1-0-2-0-and-3-0) not found CssClass

some proposals? thx in [advance](https://www.mindstick.com/blog/33258/jee-mains-and-jee-advance-exams)!

## Replies

### Reply by Pravesh Singh

Hi Ankita,\

```
public static class ControlExtension{    public static void RemoveCssClass(this HtmlControl control, string cssClassName)    {        var val =control.Attributes["class"];        val =val.Replace(cssClassName, string.Empty);       
control.Attributes["class"] = val;    }}
```

And then use it:

MyDivId.RemoveCssClass("addedClass");


---

Original Source: https://www.mindstick.com/forum/1898/how-remove-css-class-in-code-behind-dot-net-2-0

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
