blogspot visit counter

Friday, 8 March 2013

Validation controls using

Validation controls using
1.RequiredFieldValidation Control 
 2.RangeValidator Control 
 3.RegularExpressionValidator Control 
 4.CompareValidator Control 
 5.CustomValidator Control 
 6. Validation Summery
 Properties of Validation Controls:  
 ControlToValidate - Id of control Which you want to validate. 
 ErrorMessage - Message that will be displayed in the validation summary. 
 IsValid - Whether or not the control is valid. 
 Validate - Method to validate the input control and update the IsValid property. 
 Display - How the error message will display.options are given below 
 None:Message is never displayed. 
 Static:Validation message will display in the page layout. 
 Dynamic:Validation message is dynamically added to the page if validation fails. 
 Example with code: 
 1.RequiredFieldValidation:It is simple validation control which checks data is entered or not. 
 <asp:textbox id="txtEmpName" runat="server"/> 
 <asp:RequiredFieldValidator id="refid" runat="server" ControlToValidate="txtEmpName" 
 ErrorMessage="* Please enter the employee name" Display="dynamic">* 
 2.RangeValidator:It checks to see if a control value is within a valid range or not. 
 <asp:textbox id="txtDOB" runat="server"/> 
 <asp:RangeValidator id="rangeVal" runat="server" 
 ErrorMessage="* Please enter the valid date" Display="static">*</asp:RangeValidator> 
 3.RegularExpressionValidator:It can be used for email validation or any specified string based on pattern matching. 
 E-mail: <asp:textbox id="txtEmail" runat="server"/> 
 <asp:RegularExpressionValidator id="revemail" runat="server" 
 ErrorMessage="* Please enter valid e-mail ." 
 4.CompareValidator: It allows you to make comparisons between two form controls and also compare values contained with 
 these controls to constants that specified by userd. 
 New Password: <asp:textbox id="txtNewPass" runat="server"/><br /> 
 Confirm Passowrd: <asp:textbox id="txtConfirmPass" runat="server"/><br /> 
 <asp:CompareValidator id="valCompare" runat="server" 
 ControlToValidate="txtNewPass" ControlToCompare="txtConfirmPass" 
 ErrorMessage="* New Password and confirm password are not same" 
 5.CustomValidator:It allows you to write your own server-side or client-side validations logic and it can be easily applied to your web forms controls. 
 <asp:CustomValidator ID="cv" runat="server"  
 ControlToValidate="txtName" ClientValidationFunction="customvalidationr"  
 ErrorMessage="Please enter correct name"></asp:CustomValidator> 
 <asp:TextBox ID="txtName" runat="server"></asp:TextBox> 
 <asp:Button ID="btnSubmit" runat="server" /> 

The ValidationSummary control is used to display a summary of all validation errors occurred in a Web page.
The error message displayed in this control is specified by the ErrorMessage property of each validation control. If the ErrorMessage property of the validation control is not set, no error message is displayed for that validation control.

<form runat="server">
<table bgcolor="#b0c4de" cellspacing="10">
     <td align="right">Name:</td>
     <td><asp:TextBox id="txt_name" runat="server"/></td>
     <td align="right">Card Type:</td>
     <asp:RadioButtonList id="rlist_type"
     ErrorMessage="Card Type"
     <td><asp:Button id="b1" Text="Submit" runat="server"/></td>
HeaderText="You must enter a value in the following fields:"


No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...