Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

How to mark required fields in ASP.NET
xomega
#1 Posted : Monday, October 1, 2012 7:02:24 PM(UTC)
xomega



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.
  1. Define the required class for all labels in your CSS. Specify the bold font weight, e.g.
    Code:
    label.required
    {
      font-weight: bold;
    }

  2. 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"/>

Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.