Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change CSS on span tag in ASP.NET Web Forms

I am trying to change the CSS for a span tag using C# but I am unable to do so. I have tried to give it a type of HTMLGenericControl but cannot get the CssClass tag to popup in IntelliSense.

<span id="collegeSpan" runat="server" class="college">other code here</span>
like image 465
Zeeshan Raja Avatar asked Dec 16 '22 15:12

Zeeshan Raja


2 Answers

Have you tried:

collegeSpan.Attributes["class"] = "foo";
like image 110
Darin Dimitrov Avatar answered Dec 19 '22 06:12

Darin Dimitrov


Because a late answer is better then no answer at all, for the record: If you're able to alter the HTML/ASCX; use the asp:Label-control instead of a span. Label-controls are rendered to the page as a span, but it has some advantages, including the possibility to alter the "CssClass"-property :-)

like image 25
Kornelis Avatar answered Dec 19 '22 06:12

Kornelis