ASP: Assigning CSS to dynamically created Label in C#
Posted
by
Tucker
on Stack Overflow
See other posts from Stack Overflow
or by Tucker
Published on 2012-10-24T16:52:14Z
Indexed on
2012/10/24
17:00 UTC
Read the original article
Hit count: 268
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;
}
© Stack Overflow or respective owner