How remove css class in code behind .net 2.0

Total Post:183

Points:1285
C# 
C#
 4221  View(s)
Ratings:
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. Post:412

    Points:2888
    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:

    MyDivId.RemoveCssClass("addedClass");

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

Answer