Last post Jul 26, 2006 01:15 PM by bmains
Jul 24, 2006 12:03 PM|RN5A|LINK
A Web Form has a Label Web Server Control which looks like this:
<asp:Label ID="lblHeader" Height="20px" Width="100%" BackColor="black" ForeColor="lime"
CssClass="text-align:center" Font-Bold="True" Text="USING WEB CONTROLS" runat="server"/>
How do I center align the text USING WEB CONTROLS in the Label
lblHeader? I tried using the CssClass property of the Label but it doesn't render the text at the center of the
Jul 24, 2006 12:38 PM|bmains|LINK
CssClass is only meant for the name of a class in a CSS stylesheet. Try setting these values to the style property instead:
This should map over to the client-side style attribute...
Jul 24, 2006 03:23 PM|MorningZ|LINK
Also realize that an asp:label control generates as a <span> tag, which directly wraps around the content inside it, so there's no white space on either side to center inside
Jul 26, 2006 01:22 AM|RN5A|LINK
When the above line (in blue) is typed, VWD lists the different properties of the
Label like Height, BackColor, ForeColor,
Font-Bold, Text etc. but it doesn't list the style property! Why so?
Jul 26, 2006 01:30 AM|vcsjones|LINK
There is no style property for ASP.NET controls, just CssClass. The display of it is handled by individual properties like Height, BackColor, etc.
Though, you can use the style attribute and it will work correctly because the attribute will still be rendered. VS will just not recognize the attribute.
Jul 26, 2006 01:15 PM|bmains|LINK
WebControl implement IAttributeAccessor, which Label inherits from WebControl. Now what you have to understand about IAttributeAccessor is that any property not mapped to a property of the server control is automatically rendered client-side, so you can
reference things like onclick or other properties that you define client-side in your server-side control, and they will map over.
The parser/intellisense can sometimes be misleading because of that...