title: How to add an additional css class from code behind using ASP.NET?
body: <p>How to add an additional css class from code behind using ASP.NET?</p>
  
  <p><strong>CURRENT TEXTBOX</strong></p>
  
  <pre><code>&lt;asp:TextBox ID="txt" CssClass="MyClass" runat="Server" /&gt;
  </code></pre>
  
  <p><strong>DESIRED OUTPUT</strong></p>
  
  <pre><code>&lt;asp:TextBox ID="txt" CssClass="MyClass Error" runat="Server" /&gt;
  </code></pre>
  
  <hr>
  
  <p><strong>Testing</strong></p>
  
  <pre><code>txt.CssClass = "Error"
  </code></pre>
  
  <p><em>This replaces current css class.</em></p>
  
  <pre><code>txt.CssClass = "MyClass Error"
  </code></pre>
  
  <p><em>This works but but is greatly inefficient having to specify class.</em></p>
  
  <pre><code>txt.Attributes.Add("class", "Error")
  </code></pre>
  
  <p><em>This only works if no initial class is set.</em></p>
  
  <pre><code>txt.Attributes("class") += " Error"
  </code></pre>
  
  <p><em>This does not work for me.</em></p>