Home > DeveloperSection > Forums > How remove css class in code behind .net 2.0
Ankita Pandey
Ankita Pandey

Total Post:183

Posted on    January-28-2014 11:34 PM

 C# C# 

 1 Reply(s)
 2699  View(s)
Rate this:

My div contains 4 css class I want to delete one from them for adding, I do this:

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

in newest framework they can be done like this:

MyDivId.CssClass.Replace("addedClass", "");

but in .net 2.0 not found CssClass

some proposals? thx in advance!

Pravesh Singh

Total Post:411

Posted on    January-29-2014 12:39 AM

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:


Don't want to miss updates? Please click the below button!

Follow MindStick