开发者

Why won't my Label-control use CSS styling?

开发者 https://www.devze.com 2023-03-14 20:42 出处:网络
I\'m using a CSS file for styling, and it\'s working properly for all of my controls except for a label on my page.It\'s the only label on the page, so maybe it\'s a problem w/ labels in general?I\'m

I'm using a CSS file for styling, and it's working properly for all of my controls except for a label on my page. It's the only label on the page, so maybe it's a problem w/ labels in general? I'm ch开发者_如何转开发anging the Label.Text property several times, and the text gets updated properly every time, but it's just raw, non-styled text.

I have the following style listed in my CSS file:

label.myError { font-weight:bold; font-size: 25px; color:Red; font-family: Arial }

I have the following label control on my web page:

<asp:Label ID="lblError" CssClass="myError" runat="server" />

Then, at various points in my code-behind, I change the Text on the Label like this:

lblError.Text = "Please specify a " + fieldDescription + ".";


asp.net label renders as span and not label html element. Your css specifies that the class should work with labels only

label.myError { font-weight:bold; font-size: 25px; color:Red; font-family: Arial }

you just have to change label.myError to .myError to be like

.myError { font-weight:bold; font-size: 25px; color:Red; font-family: Arial }

and isA it will work.


ASP.Net will output your label as a span. So the output would be:

<span id="lblError" class="myError">hi</span>

This is why you can't use label.myError

0

精彩评论

暂无评论...
验证码 换一张
取 消