Wednesday, 8 October 2014

Required Field Validation Controls in Asp.Net C#

No comments    
categories: ,
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

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>



























0 comments:

Post a Comment