The following tutorial demonstrates how to set up ASP.NET labels, so that their font would be in bold for required fields and in normal weight for optional fields. It will utilize the CSS styles for labels to allow controlling it in one place. You can use a similar approach to implement a different way of marking the required labels.
The steps to configure the labels to use bold font for required fields are as follows.
- Define the required class for all labels in your CSS. Specify the bold font weight, e.g.
Code:
label.required
{
font-weight: bold;
}
- Specify the label and the control in your ASPX file. Bind the ASP.NET control to a data property and associate it with the label by setting the LabelID attribute to the ID of the label control. The example below illustrates this approach.
Code:
<asp:Label runat="server" ID="lblBirthDate" Text="Birth Date:"/>
<asp:TextBox LabelID="lblBirthDate" ID="ctlBirthDate" Property="<%# EmployeeObject.BirthDate %>" runat="server"/>