HOW REMOVE CSS CLASS IN CODE BEHIND .NET 2.0

Ankita Pandey

Total Post:183

Points:1285
Posted by  Ankita Pandey
C# 
C#
 3715  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. Pravesh Singh

    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");

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!