The
RequiredFieldValidator: The
RequiredFieldValidator control ensures that the required field is not empty. It
is generally tied to a text box to force input into the text box.
Property
|
Description
|
InitialValue
|
Specifies the starting value of the input control. Default value
is ""
|
Some
points about RequiredFieldValidator:
·
The
RequiredFieldValidator control is used to make an input control a required
field.
·
With
this control, the validation fails if the input value does not change from its
initial value. By default, the initial value is an empty string ("").
·
The
InitialValue property does not set the default value for the input control. It
indicates the value that you do not want the user to enter in the input
control.
·
Use
the ‘InitialValue’ property of the RequiredFieldValidator to validate controls
like combobox which have a default value. For e.g.: If your combobox has a
default item called “Select“ and you want that the user should select a value
other than the default value before submitting the form, then set the
‘InitialValue’ property of the RequiredFieldValidator to “Select “.
·
Leading
and trailing spaces of the input value are removed before validation.
Control
usage:
<asp:TextBox runat="server" ID="txtName"></asp:TextBox>
To validate this textbox:
<asp:RequiredFieldValidator ID="rfvName" runat="server"
ControlToValidate="txtName" ErrorMessage="*Required">
</asp:RequiredFieldValidator>
|
Comments
Post a Comment