Saturday 21 July 2012

ASP.NET Validation Controls with example | How to use Validation Controls in ASP.NET | RequiredFieldValidation Control in ASP.NET

                                     Hi Friends, in this article I will explain about the validation controls in ASP.NET and how to use the validation controls in ASP.NET.
                                     Validation server controls are used to validate user-input. Validation controls are used to validate the input data, because if we didn't put the validation to user input then it will display the error to the user.
In previous articles i explained some interview Questions on ASP.NET,VB.NET and SQL Server.
Validation controls are two types
1. Client side validation controls
2. Server side validation controls

Client side validation controls:
                                    Client side validation is good because the validations are done at client side before going to the server. If an error is there then the browser display the messages and doesn’t go to the server. It will decrease the burden on the server.
For this we have to dependent on the scripting languages like JavaScript, JQuery, VBscript etc.,
For developer point of view serve side is preferable because it will not fail, it is not dependent on browser and scripting language.

Server side validation controls:
                                    An important point to create Asp.NET web page for the user, we have to check all the user input.
Asp.Net provides a set of validation controls that provides easy to use and but powerful way to check for errors and, if necessary, display messages to the user.
There are six types of validation controls in ASP.NET
  • RequiredFieldValidation Control
  • CompareValidator Control
  • RangeValidator Control
  • RegularExpressionValidator Control
  • CustomValidator Control
  •  ValidationSummary 
RequiredFieldValidation Control:
                                 This control is used validate the control is not empty.Suppose if user have to enter username then that situation we use the RequiredFieldValidation Control.
How to use this is shown below.
<div>
        <asp:Label ID="Label1" runat="server" Text="Username"></asp:Label>
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
       <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server"  ErrorMessage="Please enter Username"
        ControlToValidate="TextBox1"></asp:RequiredFieldValidator>
        <asp:Button ID="Button1" runat="server" Text="Button" />
    </div>

                                 Copy and paste the above code, if use run the code and didn’t enter username textbox and click the Button then it will display the error Please Enter Username .In this situation user have to enter the username textbox otherwise it will not go to further.

No comments:

Post a Comment

© 2012-2018 Aspdotnet-Kishore.blogspot.com. All Rights Reserved.
The content is copyrighted to Kishore and may not be reproduced on other websites without permission from the owner.