开发者

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

开发者 https://www.devze.com 2023-01-01 16:55 出处:网络
I am setting 2 css class in the code behind in ASP.NET I could either do: txtBox.Attributes.Add(\"class\", \"myClass1\");

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 开发者_StackOverflow社区classes ?


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");


try

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

I think this will work.


You can also try

txtBox.CssClass = "myClass1 myClass2";


try

txtBox.Attributes.Add("class", "my_Class1 my_Class2");
0

精彩评论

暂无评论...
验证码 换一张
取 消