Advertise with us

How remove css class in code behind .net 2.0

Posted by  Ankita Pandey
 4596  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!

  1. Re: How remove css class in code behind .net 2.0

    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:


      Modified On Apr-04-2018 02:10:25 AM