Telerik Software Academy ASP.NET Web Forms Data Validation, Data Validators, Validation Groups Telerik Software Academy

Slides:



Advertisements
Similar presentations
CSCI 6962: Server-side Design and Programming Input Validation and Error Handling.
Advertisements

Tutorial 6 Creating a Web Form
Ch3: Introduction to HTML5 part 2 Dr. Abdullah Almutairi ISC 340 Fall 2014.
Meeting #5 – March 2011 – JavaScript and ASP.NET Homework Assignments Svetlin Nakov Telerik Corporation
Asp.NET Core Vaidation Controls. Slide 2 ASP.NET Validation Controls (Introduction) The ASP.NET validation controls can be used to validate data on the.
Web Development Using ASP.NET CA – 240 Kashif Jalal Welcome to week – 3-1 of…
ASP.NET Validating user input Validating user input on the client and/or server side 1ASP.NET Validating User Input.
11 ASP.NET Controls Beginning ASP.NET 4.0 in C# 2010 Chapter 6.
ASP.NET Programming with C# and SQL Server First Edition
Form Handling, Validation and Functions. Form Handling Forms are a graphical user interfaces (GUIs) that enables the interaction between users and servers.
Chapter 9 – Validating User Input Dr. Stephanos Mavromoustakos.
JavaScript Form Validation
Database-Driven Web Sites, Second Edition1 Chapter 8 Processing ASP.NET Web Forms and Working With Server Controls.
Module 7: Validating User Input.
.NET Validation Controls MacDonald Ch. 8 MIS 324 MIS 324 Professor Sandvig Professor Sandvig.
Chapter 3 Using Validation Controls. What is a Validation Control? A control that validates the value in another control Renders as an HTML tag with an.
Overview of Previous Lesson(s) Over View  Server controls are small building blocks of the graphical user interface, which includes  Text boxes  Buttons.
Overview of Previous Lesson(s) Over View  ASP.NET Pages  Modular in nature and divided into the core sections  Page directives  Code Section  Page.
Christopher M. Pascucci.NET Programming: Forms & Controls.
Programming with Microsoft Visual Basic 2012 Chapter 12: Web Applications.
1 ASP.NET ASP.NET Rina Zviel-Girshin Lecture 3. 2 Overview Cookies Validation controls Client and server side validation Validation control examples.
ASP.Net Web Applications. Characteristics of a typical data driven web application Web Server HTML Graphics Active-X Java Applets HTTP Request ADO / JDBC.
Web Application and Development Digital Media Department Unit Credit Value : 4 Essential Learning time : 120 hours Digital Media.
ASP.Net, Web Forms and Web Controls 1 Outline Web Controls Text and Graphics Controls AdRotator Control Validation Controls.
Web Programming: Client/Server Applications Server sends the web pages to the client. –built into Visual Studio for development purposes Client displays.
BIT 285: ( Web) Application Programming Lecture 08: Thursday, January 29, 2015 Data Validation, Using Validators Instructor: Craig Duckett.
Validation and Rich controls 1www.tech.findforinfo.com.
C# Tutorial -1 ASP.NET Web Application with Visual Studio 2005.
Microsoft Visual Basic 2005 CHAPTER 7 Creating Web Applications.
ASP.NET Event Handlers Database -> Browser ->Shopping Basket Validators.
Using Client-Side Scripts to Enhance Web Applications 1.
ITCS373: Internet Technology Lecture 5: More HTML.
Lesson 12 Adding Validation To The Movie Database.
SQL INJECTIONS Presented By: Eloy Viteri. What is SQL Injection An SQL injection attack is executed when a web page allows users to enter text into a.
AUC Technologies Projects Consulting, Development, Mentoring, and Training Company ASP.NET Validation Control Presented By : Muhammad Atif Hussain Deputy.
VALIDATION CONTROLS.  Validation Controls are primarily used to validate, or verify the data entered by user into a web form.  Validation controls attempt.
HTML Forms. Slide 2 Forms (Introduction) The purpose of input forms Organizing forms with a and Using different element types to get user input A brief.
Building Applications using ASP.NET and C# / Session 4 / 1 of 15 Session 4.
CSCI 4230 Homework #3 Group Three Samer Al Jefri * Kevin Odom * David Hood * JD * Phil.
Session 6: Validating User Input. Outline Overview of User Input Validation Client-Side and Server-Side Validation ASP.NET Validation Controls Using Validation.
© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 User Input Validating.
INT222 - Internet Fundamentals Shi, Yue (Sunny) Office: T2095 SENECA COLLEGE.
©SoftMooreSlide 1 Introduction to HTML: Forms ©SoftMooreSlide 2 Forms Forms provide a simple mechanism for collecting user data and submitting it to.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
Vijayalakshmi G M Validation Controls.
13 Copyright © 2004, Oracle. All rights reserved. Adding Validation and Error Handling.
HTML5 Forms Forms are used to capture user input …
ASP + JavaScript Client and Server scripts. Link 1 function MyClick(){ document.write("MyClick"); } function MyFunction1(){ alert("My Function 1"); }
Text INTRODUCTION TO ASP.NET. InterComm Campaign Guidelines CONFIDENTIAL Simply Server side language Simplified page development model Modular, well-factored,
Learning Aim C.  In this section we will look at how text, tables, forms and frames can be used in web pages.
Beginning ASP.NET in C# and VB Chapter 9
Tutorial 6 Creating a Web Form
Using Personalization Creating user profiles Retrieving, changing, and saving profile properties Using validation controls Using the Forms Designer.
Validation Controls Assist your users with providing the correct type of input for your application Assist your users with providing the correct type of.
Chapter 9 Validating User Input. Objectives What user input is and why it’s important to validate it What ASP.NET has to offer to aid you in validating.
IS1500: Introduction to Web Development
Validation & Rich Controls
Validation Controls, User Controls, Master Pages
Web Programming– UFCFB Lecture 17
Unit 27 - Web Server Scripting
12/9/2018 Session 9.1 Calendar and Validation Controls Using Sessions
JavaScript Form Validation
Static and Dynamic Web Pages
PART 2.
Web Development Using ASP .NET
MIS 3200 – Unit 2.2 Outline What’s the problem with bad data?
Server Controls Validation Controls
.NET Validation Controls
Validation & Rich Controls
Presentation transcript:

Telerik Software Academy ASP.NET Web Forms Data Validation, Data Validators, Validation Groups Telerik Software Academy ASP.NET Web Forms

1. Data Validation 2. Validation Controls 3. Common Properties 4. Validation Group

Validating Data in Web Applications

 When a user enters data in a form the programmer expects a certain data type  Invalid input can break the application logic  Input data validation means  Comparing a field to specific values or a range of acceptable values  Checking for required interdependencies between the fields

 Predefined input formats usually follows some rules defining the acceptable set of values  Limitation about the length of a field  Allow empty value or not  Accepting digits only or not  A range of acceptable values  E.g. regular expression  Mathematical formula  E.g. field A > field B

 The validation is always done on the server  When the client request is processed  Additionally some validation rules could be performed at the client side  In all cases the main part of the validation should be done at the server  A mischievous user can alter the validation on the client

 Data validation is important!  Invalid data could cause many problems  Crashes of the application  Execution of SQL queries (SQL-injection)  Revealing protected data  Example:  A user can enter very long text into a Web page  This could cause exceptions at the server side

ASP.NET Controls for Data Validation

 ASP.NET simplifies the process of validation by supplying a set of validation controls  RequiredFieldValidator  Ensures the field is not left empty  CompareValidator  Compares the input data from a control to the data in another control or to a constant value  Example:  When a password needs to be entered twice

 RangeValidator  Checks if the input is in given range of values  Between two constant values, e.g. [5..10]  Between two values of other controls  CustomValidator  Provides a standard way for writing your own validation logic  The programmer needs to implement the logic

 RegularExpressionValidator  Checks the input against a regular expression pattern, e.g. [1-9][0-9]+  Examples:  Checking SSN, addresses, phones, etc.  Visual Studio provides many predefined patterns for the most common validations

 ValidationSummary  A summary of all errors generated by the validation controls on the page  Provides an information about all errors in all page fields  Usually placed near the submit button

 After the validator is placed on the page you can assign its attributes (properties)  ControlToValidate, ErrorMessage, Text, … <asp:type_of_validatorID="validator_id"runat="server"ControlToValidate="control_id"ErrorMessage="error_message_for_summary"Display="static|dynamic|none"Text="Text_to_display_by_input_control"></asp:type_of_validator>

 ControlToValidate  Sets which control to be validated  One validator validates one particular field  IsValid  Indicates if the input is valid  EnableClientScript  Sets whether a client side validation is performed  Server side validation is always performed

 RangeValidator and CompareValidator have the Type property  Specifies the type of the data validated  The possible values are String, Integer, Double, Date and Currency  The specified range of values belongs to the same type, e.g. [ … ]  Visual Studio automatically sets this property when you specify ControlToValidate

 ErrorMessage  A message that is displayed if the input is found to be invalid  If the Text property is set it is shown instead  When a ValidationSummary is defined  The value of the Text property is shown at the validation control’s position  ErrorMessage is displayed in the ValidationSummary

 The Display property sets the layout of the error message  Affects messages which are displayed at the validation control’s position  Messages shown in the ValidationSummary control are unaffected  Applied when the form use FlowLayout only  Static – fixed space is allocated for the error  Dynamic – space is allocated only if an error should be displayed, otherwise nothing is shown

<asp:CompareValidator ID="CompareValidatorPassword" runat="server" ControlToCompare="TextBoxPassword" runat="server" ControlToCompare="TextBoxPassword" ControlToValidate="TextBoxRepeatPass" ControlToValidate="TextBoxRepeatPass" ValueToCompare="Text" ForeColor="Red" ValueToCompare="Text" ForeColor="Red" ErrorMessage="Password doesn't match!" /> ErrorMessage="Password doesn't match!" /> <asp:Button ID="BtnSubmit" runat="server" Text="Submit" /> Text="Submit" /> * Note: due to a design flaw in the CompareValidator, when the second control is empty or contains whitespace only, the validator is not executed at all!

Live Demo

<asp:RequiredFieldValidator ID="RequiredFieldValidator " ID="RequiredFieldValidator " runat="server" ForeColor="Red" Display="Dynamic" runat="server" ForeColor="Red" Display="Dynamic" ErrorMessage="An address is required!" ErrorMessage="An address is required!" ControlToValidate="TextBox " /> ControlToValidate="TextBox " /><asp:RegularExpressionValidator ID="RegularExpressionValidator " ID="RegularExpressionValidator " runat="server" ForeColor="Red" Display="Dynamic" runat="server" ForeColor="Red" Display="Dynamic" ErrorMessage=" address is incorrect!" ErrorMessage=" address is incorrect!" ControlToValidate="TextBox " ControlToValidate="TextBox " ValidationExpression="[a-zA-Z][a-zA-Z0-9\-\.]+[a-zA- /> ValidationExpression="[a-zA-Z][a-zA-Z0-9\-\.]+[a-zA- />

 The Page.IsValid property is evaluated as a logical "AND" of all validation controls on the page private void ButtonSubmit_Click( object sender, EventArgs e) object sender, EventArgs e){ if (Page.IsValid) if (Page.IsValid) { LabelMessage.Text = "The page is valid!"; LabelMessage.Text = "The page is valid!"; // Perform some logic here // Perform some logic here } // An else clause is unneeded – the page will // An else clause is unneeded – the page will // be returned to the user and all error // be returned to the user and all error // messages will be displayed // messages will be displayed}

Live Demo

 You can group validation controls  Scenario  A PostBack is initiated from a control (button) that has a validation group set  Only validation controls of that group are validated  You can explicitly cause validation from code- behind by calling the Page.Validate("groupName") method

 Page.IsValid reflects the validity of all groups validated so far  This includes  Validation as a result of PostBack  Validation as a result of call to Validate()

Live Demo

Questions?

1. Create a form to register users with fields for preferred user name, password, repeat password, first name, last name, age, , local address, phone and an “I accept” option. All fields are required. Valid age is between 18 and 81. Display error messages in a ValidationSummary. Use a regular expression for the and phone fields. 2. Separate the fields in groups and validate them using Validation Groups. The Validation Groups should be at least three – Logon Info, Personal Info, Address Info.

3. * Add a radio button to choose the gender (male / female). If the user is male, dynamically display a list of check boxes for choosing his favourite cars (e.g. BMW, Toyota, etc.). If the user is female display a drop-down list to allow her select her favourite coffee (e.g. Lavazza, New Brazil, etc.). Note that selecting a coffee is optional for the female users. Implement this by server PostBacks. 4. * Implement the previous with client-side JavaScript.