Click here to Skip to main content
15,879,095 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
With other elements created in C#, I can use either this type of code:

C#
txtarAccountCodes = new HtmlTextArea
{
    CssClass = "clearonreset"
};


...or this:

C#
txtarAccountCodes.CssClass = "clearonreset";


...to assign a CSS Class to an element, but neither is allowed with HtmlTextArea elements. Is there a way to assign a CSS class to HtmlTextArea elements server-side?
Posted

To set the CSS class of an HtmlTextArea control, or anything else defined in the System.Web.UI.HtmlControls namespace, you'll have to use the Attributes collection[^]:
C#
txtarAccountCodes.Attributes["class"] = "clearonreset";

Alternatively, you could use the TextBox control with the TextMode set to MultiLine:
C#
txtarAccountCodes = new TextBox
{
    TextMode = TextBoxMode.MultiLine,
    CssClass = "clearonreset"
};
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 11-Aug-15 12:33pm    
Sure, a 5.
—SA
 
Share this answer
 
Comments
B. Clay Shannon 11-Aug-15 12:16pm    
I can set CSS Styles, but setting a CSS Class is a different animal, methinks.
Sergey Alexandrovich Kryukov 11-Aug-15 12:20pm    
Do you need to style an element or "same animal"? :-)
—SA
B. Clay Shannon 11-Aug-15 12:25pm    
I don't need to style it, I need to assign it a CSS class, so that the jQuery will act on it in certain circumstances. The link you provided showed how to set up styles, but styles != classes.
Sergey Alexandrovich Kryukov 11-Aug-15 12:32pm    
You are right, it's not the same. But using a class just for a condition for jQuery sounds pretty pointless. You can use just jQuery for this purpose, without any server-side code. And, among other thing, you can add/remove any class with jQuery. It all depends on what you want to achieve.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900