How to get access to “CssClass” property for server element isn't WebControl in ASP.NET?

Total Post:51

Points:359
 1344  View(s)
Ratings:
Rate this:

I have ordinary div like this:

<div id="myCoolElement" runat="server"></div>

I want use the construction to set CssClass for myCoolElement like this:

myCoolElement.CssClass("mycoolstyle");

But CssClass property is supported only for WebControls.

How I can set CssClass for my element without creating WebControl?

  1. Post:88

    Points:616
    Re: How to get access to “CssClass” property for server element isn't WebControl in ASP.NET?

    You can do like this 

    myCoolElement.Attributes["class"] = "mycoolstyle";

      Modified On Apr-07-2018 05:08:34 AM
  1. Post:102

    Points:714
    Re: How to get access to “CssClass” property for server element isn't WebControl in ASP.NET?

    Try this.

     myCoolElement.Attributes.Add("class", "mycoolstyle");

Answer