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:
if(yourCondition) {
var css = "myClass";
if(String.IsNullOrWhiteSpace(element.CssClass))
element.CssClass = css;
else
element.CssClass += " " + css;
}
you can use attribute of ui controls
firstName.Attributes["css"]="Your Class Name";
You can implement adding cssClass like
firstName.CssClass = "input left selected";
Or
make onClick event for textbox
<asp:TextBox ID="firstName" CssClass="input left" runat="server" Text="First Name" OnClick="firstName_Click" />
Then in code-behind:
void firstName_Click(Object sender, EventArgs e) {
MyTextBox.CssClass = "input left selected";
}
You can just do this:
firstName.CssClass = "input left selected".
If you want to append to any existing class names, do this:
firstName.CssClass += " selected";
It's just a string property of WebControl:
firstName.CssClass += " selected";
I think you could do that in the normal way something like below:
if (value.Equals(true))
{
firstName.CSSClass = "input left selected";
}
Hope this helps!!