You can do it like this, but please do not do it. For the sake of your fellow developers in the past, present and future, separate your code from your design. Now, if you have to write markup in the code behind, this is definitely a way to do it.
However, if all you need to do is add a literal / span / textbox with a specific class, you can do something like this:
(Given that you have a panel with runat="server" called "myPanel")
myPanel.Controls.Add(new Label { Text = "Hello!", CssClass = "specific-class" });
Filip Ekberg
source share