Home > DeveloperSection > Forums > How to get access to “CssClass” property for server element isn't WebControl in ASP.NET?
Hugh Jackman
Hugh Jackman

Total Post:52

Points:366
Posted on    December-11-2014 10:34 PM

 ASP.Net C#  ASP.NET MVC  CSS 
Ratings:


 2 Reply(s)
 601  View(s)
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?



jacob rasel
jacob rasel

Total Post:88

Points:616
Posted on    December-12-2014 6:09 AM

You can do like this

 

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


Mark Devid
Mark Devid

Total Post:101

Points:707
Posted on    December-12-2014 6:53 AM

Try this.

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


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

Follow MindStick