Wednesday 5 June 2013

All About Validation Controls

Validation Controls.

How to use CustomValidator validation control with example in asp.net

Introduction: While creating user input form e.g. registration where user inputs the details like Name, email address, password and confirm password ,Website URL,comments/messages etc. we have to implement validations on the form so that incorrect data could not be submitted to server. Asp.net provides Validation controls like CompareValidator, CustomValidator , RangeValidator, RegularExpressionValidator, RequiredFieldValidator etc to apply validations on asp.net web page.  
In previous article i explained How to use RequiredFieldValidator validation control with example in asp.net and How to use CompareValidator validation control with example in asp.net and How to use RegularExpressionValidator validation control with example in asp.net and How to use RangeValidator validation control with example in asp.net. Now in this article I will explain how to use CustomValidator control to check the validity of the comments/message length before submitting to server for processing otherwise error message will be displayed to the user.  


CustomValidator vaidation control example in asp.net 

How to use RangeValidator validation control with example in asp.net

Introduction: While creating user input form e.g. registration where user inputs the details like Name, email address,Age,Date of Birth, password and confirm password etc. we have to implement validations on the form so that incorrect data could not be submitted to server. Asp.net provides Validation controls like CompareValidator, CustomValidator,RangeValidator, RegularExpressionValidator, RequiredFieldValidator etc to apply validations on asp.net web page. 
In previous article i explained How to use RequiredFieldValidator validation control with example in asp.net and How to use CompareValidator validation control with example in asp.net. and How to use RegularExpressionValidator validation control with example in asp.net.and How to use CustomValidator validation control with example in asp.net .Now in this article I will explain how to use RangeValidatocontrol to check the data entered is valid or not i.e. withing the range specified before submitting to server for processing otherwise error message will be displayed to the user.

RangeValidatior validation control example in asp.net


How to use RegularExpressionValidator validation control with example in asp.net

Introduction: While creating user input form e.g. registration where user inputs the details like Name, email address, password and confirm password ,Website URL etc. we have to implement validations on the form so that incorrect data could not be submitted to server. Asp.net provides Validation controls like CompareValidator, CustomValidator, RangeValidator, RegularExpressionValidator, RequiredFieldValidator etc to apply validations on asp.net web page. 
In previous article i explained How to use RequiredFieldValidator validation control with example in asp.net and How to use CompareValidator validation control with example in asp.net and How to use RangeValidator validation control with example in asp.net and How to use CustomValidator validation control with example in asp.net .Now in this article I will explain how to use RegularExpressionValidator control to check the validity of the email address and website URL before submitting to server for processing otherwise error message will be displayed to the user.  
Note: Email Id should be in email format e.g. me@mydomein.com and Website URL should be like http://www.webcodeexpert.com/.

 In this example I have demonstrated 3 ways to use RegularExpressionValidator control.
RegularExpressionValidator validation control example in asp.net

How to use CompareValidator validation control with example in asp.net

Introduction: While creating user input form e.g. registration where user inputs the details like Name, email address, password and confirm password etc. we have to implement validations on the form so that incorrect data could not be submitted to server. Asp.net provides Validation controls like CompareValidator, CustomValidator, RangeValidator, RegularExpressionValidator, RequiredFieldValidator etc to apply validations on asp.net web page. 
In previous article i explained How to use RequiredFieldValidator validation control with example in asp.net and How to use RegularExpressionValidator validation control with example in asp.net and How to use RangeValidator validation control with example in asp.netand How to use CustomValidator validation control with example in asp.net .Now in this article I will explain how to use CompareValidatocontrol to compare the data in two TextBoxes e.g. Password TextBox and Confirm password TextBox should be same before submitting to server for processing otherwise error message will be displayed to the user.
 In this example I have demonstrated 3 ways to use CompareValidator control. 

CompareValidator validation control example in asp.net

How to use RequiredFieldValidator validation control with example in asp.net

IntroductionWhile creating user input form e.g. registration form  or contact us form etc where user inputs the details, we have to implement validations on the form so that empty or incorrect data could not be submitted to server. Asp.net provides Validation controls like CompareValidator, CustomValidator, RangeValidator, RegularExpressionValidator, RequiredFieldValidator etc to apply validations on asp.net web page. In this article I will explain how to use RequiredFieldValidator control to force the user to enter in TextBoxi.e. TextBox can't be left blank on submitting to server. 
In previous article i explained How to use CompareValidator validation control with example in asp.net and How to use RegularExpressionValidator validation control with example in asp.net  and How to use RangeValidator validation control with example in asp.net. and
How to use CustomValidator validation control with example in asp.net .In this example I have demonstrated 3 ways to use RequiredFieldValidator control. I will post how to user other validation controls in my next articles. 


RequiredFieldValidator validation control example in asp.net


How to validate CheckBoxList using JavaScript in Asp.net(C#, VB)

IntroductionIn the previous article I explained How to Fill CheckBoxList from Sql Server table in asp.net(C#,VB)  and Fill CheckBoxList based on DropDownList selection in asp.net(C#, VB)  and How to get CheckBoxList selected items in comma separated format in asp.net(C#,VB) and  how to  show Message box in asp.net website using JavaScript and how to redirect visitor from one website to another website using java script and How to call java script function from code behind file in asp.net Now in this article I am going to explain how to validate CheckBoxList control i.e. to ensure at least one item is selected in the CheckBoxList. I am using CustomValidator control andJavaScript to validate. Let’s understand by an example.

checkbox validation in asp.net

  • In the <HEAD> tag of the design page(.aspx) create the JavaScript function to validate the CheckBoxList.

How to show Validation guidelines in web forms using JavaScript in Asp.net ?

Introduction: In previous articles i explained how to  show Message box in asp.net website using JavaScript and how to redirect visitor from one website to another website using java script and How to call java script function from code behind file in asp.net.In this article I will explain how to show validation guidelines to the user while filling forms like contact us form, login form etc. Whenever user takes mouse cursor on the text boxes it display what to enter in that textbox. So it is very user friendly because user get to know what to enter and in what format to enter the value in fields. Lets understand usingJavaScript.
  • It will look like this:  
http://webcodeexpert.blogspot.in/
  • Now In the design page (.aspx) write the JavaScript functions in the Head tag as: 

What is Page.IsValid and Page.Validate in Asp.net ?

IntroductionIn previous articles i explained the Difference between Delete and Truncate in sql server
 and Difference between Response.Redirect and Server.Transfer in asp.net and Difference between DataSet and DataTable in asp.net and 15 main Difference between DataSet and DataReader in asp.net and 20 main differences between Stored procedures and Functions in Sql Server are most important interview questions.Similarly Difference betweenPage.Isvalid and Page.Validate is also important interview question. When we create a web form for taking user input e.g. login form or contact us form in asp.net we have to validate the user input before submitting to server so that only validated data could be submitted to server.
We can apply client side validations through Validation controls provided by Visual Studio such as RequiredFieldValidator , RangeValidatorCompareValidator,RegularExpressionValidator , CustomValidator etc.

After validating we may thing that we have built a secure application but a hacker could disable JavaScript and bypass all our validators ! This is where the Page.Validate() method and more importantly, the Page.IsValid property come in.

Validate and upload image files in asp.net

Introduction: It is always better to validate the file extension before uploading file i.e. you want that user can upload only the files that you want e.g. if you want the user can upload only jpg, jpeg, png, gif files then you have to write the code that can check the extension of the file the user is going to upload. Here is the way:
  • Place a FileUpload control and a button control on design page(.aspx)
<asp:FileUpload ID="FileUpload1" runat="server" />
        <asp:Button ID="btnUploadImage" runat="server" Text="upload Image"
            onclick="btnUploadImage_Click"  />


JavaScript validation in asp.net website

Introduction : In previous articles i explained how to  show Message box in asp.net website using JavaScript and how to redirect visitor from one website to another website using java script and How to call java script function from code behind file in asp.net  and How to show Validation guidelines in web forms using JavaScript in Asp.net ?.An important point while creating ASP.NET Websites is to be able to check that the information users enter is valid. ASP.NET provides a set of validation controls that provide an easy-to-use but powerful way to check for errors and, if necessary, display messages to the user. Similarly we can also create functions in JavaScript to validate the data before submitted to server thus saving the server time and overhead.

 Javascript validation example in asp.net

How to check and validate file extension before uploading a file through FileUpload control in asp.net | Use of RegularExpressionValidator control to validate file extension before uploading file through FileUpload control in asp.net

Introduction: Sometimes it is required to validate the file extension before uploadingfile i.e. you want that user can upload only the files that you want e.g. if you want the user can upload only Word  and Excel  files(doc, docx, xls, xlsx ) then you have to check the extension of the file the user is going to upload.
  • Place a FileUpload control and the RegularExpressionValidator control ,ValidationSummary control and a Button Control on design page(.aspx)
  <asp:FileUpload ID="FileUpload1" runat="server" />

<asp:RegularExpressionValidator id="RegularExpressionValidator1"
runat="server"
ErrorMessage="Only excel or word file is allowed!"
ValidationExpression ="^.+(.xls|.XLS|.xlsx|.XLSX|.doc|.DOC|.docx|.DOCX)$"
ControlToValidate="FileUpload1"
Display="None">
 </asp:RegularExpressionValidator>

Validate file extension while uploading image or file through File Upload control using JavaScript in asp.net | Use of CustomValidator control to validate file extension before uploading image or file through FileUpload control in asp.net

Introduction: In previous articles i explained how to show Message box in asp.net website using JavaScript and how to redirect visitor from one website to another website using java script and How to call java script function from code behind file in asp.net  and How to show Validation guidelines in web forms using JavaScript in Asp.net ?.Sometimes it is required to validate the file extension before uploading file i.e. you want that user can upload only the files that you want e.g. if you want the user can upload only jpg, jpeg, png, gif, doc, docx, xls, xlsx files then you have to check the extension of the file the user is going to upload.

  • Write the JavaScript function to validate file extension in the Head tag of your design page(.aspx) as:
Note: We are creating JavaScript function to validate the file extension and calling that function on the CustomValidator control. So this article also demonstrates the use ofCustomValidator control.

No comments:

Post a Comment