你如何编程应用CSS类一个asp.net控制? [英] How do you programmatically apply a css class to an asp.net control?
本文介绍了你如何编程应用CSS类一个asp.net控制?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我不知道我该如何通过C#中的后端应用CSS类ASP.NET控件(文本框在这种情况下)。例如:
I'm wondering how I can apply a CSS class to an ASP.NET Control (TextBox in this case) through the backend in C#. For example:
<asp:TextBox ID="firstName" CssClass="input left" runat="server" Text="First Name" />
我想另一个类添加到选择元素,如果值是真的,我测试的后端。
I'd like to add another class to the element "selected" if a value is true that I test for on the backend.
<asp:TextBox ID="firstName" CssClass="input left selected" runat="server" Text="First Name" />
什么是做到这一点的最好方法是什么?谢谢!
What is the best way to do this? Thanks!
推荐答案
您只需做到这一点:
firstName.CssClass = "input left selected".
如果您要附加到任何现有的类名,这样做:
If you want to append to any existing class names, do this:
firstName.CssClass += " selected";
这篇关于你如何编程应用CSS类一个asp.net控制?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文