ASP: Assigning CSS to dynamically created Label in C#
- by Tucker
I'm trying to figure out how to apply CSS to a Label created in C#. Everything compiles and runs, it just doesn't seem to be applying the CSS. The CSS is in the file linked to in the site master page. Everything else in the CSS file is being applied as it should be.
Codebehind:
...
Label label = new Label();
SqlCommand command = new SqlCommand("SELECT Q_Text FROM HRA.dbo.Questions WHERE QID = 1");
command.Connection = connection;
reader = command.ExecuteReader();
reader.Read();
label.Text = reader["Q_Text"].ToString();
label.ID = "rblabel";
label.CssClass = "rblabel";
reader.Close();
...
ASP:
<asp:Content runat="server" ID="BodyContent" ContentPlaceHolderID="MainContent">
<asp:PlaceHolder ID="holder" runat="server">
</asp:PlaceHolder>
</asp:Content>
CSS:
.rblabel {
text-align:left;
padding-left: 2em;
font-size: 4em;
}