REQUIRED FIELD VALIDATION
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.
RequiredFieldValidator validation control make an asp.net web server input control as like a mandatory field.
DEMO
You can use it to make sure that the user has entered something in a TextBox control
First - Add - New WebForm - Select Textbox & DropDownlist from ToolBox
Next - Go to - ToolBox - Validation -Select - Required Field Validation - for Textbox & DropDownlist
Next - Select Required Field Validation - F4 press Property window below like that
Select - DropDownList -Required Field Validation - Error Message write required - Control to validate DropDownList ID - Initial values Put Select Country or your dropdownlist values - index 0
Next - Click Save Button Without Fill Values Show below like that Error Message Show
Next - Fill Values After Click - Save Button - Save the values
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.
RequiredFieldValidator validation control make an asp.net web server input control as like a mandatory field.
DEMO
Html Coding
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<table>
<tr><td>
<asp:Label ID="Label1" runat="server" Text="Name"></asp:Label>
<td>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1"
runat="server"
ControlToValidate="TextBox1" ErrorMessage="*"></asp:RequiredFieldValidator>
</td></td></tr>
<tr><td>
<asp:Label ID="Label2" runat="server" Text="Country"></asp:Label>
</td><td>
<asp:DropDownList ID="DropDownList1" runat="server">
<asp:ListItem>Select Country</asp:ListItem>
<asp:ListItem>Australia</asp:ListItem>
<asp:ListItem>India</asp:ListItem>
<asp:ListItem>UK</asp:ListItem>
<asp:ListItem>US</asp:ListItem>
</asp:DropDownList>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2"
runat="server"
ControlToValidate="DropDownList1"
ErrorMessage="Please Select Country"
InitialValue="Select Country"></asp:RequiredFieldValidator>
</td></tr>
<tr><td colspan="2">
<asp:Button ID="Button1" runat="server" Text="Save" />
</td></tr>
</table>
</div>
</form>
</body>
</html>
You can use it to make sure that the user has entered something in a TextBox control
Property | Description |
---|---|
BackColor | The background color of the RequiredFieldValidator control |
ControlToValidate | The id of the control to validate |
Display | The display behavior for the validation control. Legal values are:
|
EnableClientScript | A Boolean value that specifies whether client-side validation is enabled or not |
Enabled | A Boolean value that specifies whether the validation control is enabled or not |
ErrorMessage | The text to display in the ValidationSummary control when validation fails.Note: This text will also be displayed in the validation control if the Text property is not set |
ForeColor | The foreground color of the control |
id | A unique id for the control |
InitialValue | Specifies the starting value of the input control. Default value is "" |
IsValid | A Boolean value that indicates whether the control specified by ControlToValidate is determined to be valid |
runat | Specifies that the control is a server control. Must be set to "server" |
Text | The message to display when validation fails |
First - Add - New WebForm - Select Textbox & DropDownlist from ToolBox
Next - Go to - ToolBox - Validation -Select - Required Field Validation - for Textbox & DropDownlist
Next - Select Required Field Validation - F4 press Property window below like that
Property Select - Error Message Change Required - Select Control to Validate TextBox id Values for Control Textbox
Select - DropDownList -Required Field Validation - Error Message write required - Control to validate DropDownList ID - Initial values Put Select Country or your dropdownlist values - index 0
Next - Press F5 - Run the Program
Next - Click Save Button Without Fill Values Show below like that Error Message Show
Next - Fill Values After Click - Save Button - Save the values
0 comments:
Post a Comment