Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add two CSS Class to control in the code behind?

Tags:

I am setting 2 css class in the code behind in ASP.NET

I could either do:

txtBox.Attributes.Add("class", "myClass1"); txtBox.Attributes.Add("class", "myClass2"); 

it's always apply one Class .. How can i add thw two classes ?

like image 201
Amr Badawy Avatar asked Jun 02 '10 08:06

Amr Badawy


People also ask

How do you add two classes in CSS?

To specify multiple classes, separate the class names with a space, e.g. <span class="left important">. This allows you to combine several CSS classes for one HTML element. Naming rules: Must begin with a letter A-Z or a-z.

How can we call CSS class in code behind in asp net?

If you want to add attributes, including the class, you need to set runat="server" on the tag. Thanks, I was sure it would be this simple. @Tyler, no. This adds a new class name to the control.

Can an element have two CSS classes?

An element is usually only assigned one class. The corresponding CSS for that particular class defines the appearance properties for that class. However, we can also assign multiple classes to the same element in CSS.

Can there be 2 classes in HTML?

HTML elements can be assigned multiple classes by listing the classes in the class attribute, with a blank space to separate them.


1 Answers

The Add method is actually a Put, since it replaces the value behing the key "class". In HTML/css you can have several classes by separating with a space.

txtBox.Attributes.Add("class", "myClass1 myClass2"); 
like image 101
Marc Avatar answered Nov 06 '22 00:11

Marc