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.

Slides:



Advertisements
Similar presentations
Lecture 6/2/12. Forms and PHP The PHP $_GET and $_POST variables are used to retrieve information from forms, like user input When dealing with HTML forms.
Advertisements

JavaScript Forms Form Validation Cookies. What JavaScript can do  Control document appearance and content  Control the browser  Interact with user.
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 controls  standard controls  validation controls  rich controls.
DT211/3 Internet Application Development JSP: Processing User input.
JavaScript Forms Form Validation Cookies CGI Programs.
ASP.NET Validating user input Validating user input on the client and/or server side 1ASP.NET Validating User Input.
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.
Lesson 8 Creating Forms with JavaScript
CST JavaScript Validating Form Data with JavaScript.
JavaScript Form Validation
1 CS 3870/CS 5870 Static and Dynamic Web Pages ASP.NET and IIS.
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.
Scott Marino MSMIS Summer Session Web Site Design and Authoring Session 9 Scott Marino.
1 Forms A form is the usual way that information is gotten from a browser to a server –HTML has tags to create a collection of objects that implement this.
1 CS 3870/CS 5870 Static and Dynamic Web Pages ASP.NET and IIS.
Chapter 5 Java Script And Forms JavaScript, Third Edition.
Chapter 6: Forms JavaScript - Introductory. Previewing the Product Registration Form.
Validation Controls. Validation Server Controls These are a special type of Web server control. They significantly reduce some of the work involved in.
CSCI 6962: Server-side Design and Programming Introduction to AJAX.
Telerik Software Academy ASP.NET Web Forms Data Validation, Data Validators, Validation Groups Telerik Software Academy
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.
XHTML Introductory1 Forms Chapter 7. XHTML Introductory2 Objectives In this chapter, you will: Study elements Learn about input fields Use the element.
1 ASP.NET ASP.NET Rina Zviel-Girshin Lecture 3. 2 Overview Cookies Validation controls Client and server side validation Validation control examples.
WEEK 3 AND 4 USING CLIENT-SIDE SCRIPTS TO ENHANCE WEB APPLICATIONS.
Execution Environment for JavaScript " Java Script Window object represents the window in which the browser displays documents. " The Window object provides.
1 VU. 2 CS101 Introduction to Computing Lecture 15 More on Interactive Forms (Web Development Lecture 5)
© 2000 – All Rights Reserved - Page 1 Introduction to JavaScript Programming Part Two.
Introduction to JavaScript + More on Interactive Forms.
JavaScript is a client-side scripting language. Programs run in the web browser on the client's computer. (PHP, in contrast, is a server-side scripting.
ASP.Net, Web Forms and Web Controls 1 Outline Web Controls Text and Graphics Controls AdRotator Control Validation Controls.
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.
Section 17.1 Add an audio file using HTML Create a form using HTML Add text boxes using HTML Add radio buttons and check boxes using HTML Add a pull-down.
Using Client-Side Scripts to Enhance Web Applications 1.
JavaScript, Fourth Edition Chapter 5 Validating Form Data with JavaScript.
Web Interfaces, Forms & Databases Databases Snyder p HTML Basics Snyder p JavaScript Snyder Chapter 18.
CO1552 Web Application Development HTML Forms, Events and an introduction to JavaScript.
JavaScript - A Web Script Language Fred Durao
JavaScript, jQuery, and Mashups Incorporating JavaScript, jQuery, and other Mashups into existing pages.
Lesson 12 Adding Validation To The Movie Database.
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.
Introduction to JavaScript CS101 Introduction to Computing.
44238: Dynamic Web-site Development Client Side Programming Ian Perry Room:C48 Extension:7287
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.
ASP.NET 4 Unleashed Chapter 1. .aspx page: contains C# script and HTML code including tags. Listing 1.1 FirstPage.aspx.
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.
1 CSC160 Chapter 7: Events and Event Handlers. 2 Outline Event and event handlers onClick event handler onMouseOver event handler onMouseOut event handler.
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.
Vijayalakshmi G M Validation Controls.
HTML FORMS The TEXT Object Presented By: Ankit Gupta.
Text INTRODUCTION TO ASP.NET. InterComm Campaign Guidelines CONFIDENTIAL Simply Server side language Simplified page development model Modular, well-factored,
Beginning ASP.NET in C# and VB Chapter 9
ASP.NET Part 2 Instructor: Charles Moen CSCI/CINF 4230.
Client-side (JavaScript) Validation. Associating a function with a click event – Part 1 Use the input tag’s onclick attribute to associate a function.
Validation Controls Assist your users with providing the correct type of input for your application Assist your users with providing the correct type of.
Validation & Rich Controls
Web Programming– UFCFB Lecture 17
Unit 27 - Web Server Scripting
Static and Dynamic Web Pages
PART 2.
Murach's JavaScript and jQuery (3rd Ed.)
Validation & Rich Controls
Presentation transcript:

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 error message Each validation control is associated with one specific ControlToValidate (e.g. Textbox, DropdownList, etc.) A particular web control can have multiple different types of validators

Types of Validators RequiredFieldValidator RangeValidator CompareValidator RegularExpressionValidator CustomValidator Others

Listing 3.1 OrderForm.aspx A RequiredFieldValidator is used to ensure that required fields are not left blank. All Validator controls have two important properties: 1.ControlToValidate 2.Text

A CompareValidator is can be used to perform various comparison operations. In this case we are comparing the data entered to a desired data type. We are ensuring that the user actually enters numbers for the price and quantity.

When page first loads... If user enters valid data and clicks the submit button, the page will post to the server and the button’s OnClick event handler will be triggered.

If user leaves a required field blank. If user puts wrong type of data into a field. Handled via a RequiredFieldValitdator. Handled via a CompareValidator. NOTE: in these cases, the page will NOT post. Validation checks are handled at the client, not the server.

Listing 3.1 HTML

Validator controls render HTML tags. Initially, these are hidden. JavaScript code is created to handle client-side validation.

Listing 3.2 ValidationImage.aspx You can make a Validator display an image instead of text by using an HTML tag in the Text property.

Listing 3.3 ShowSetFocusOnError.aspx The SetFocusOnError property can be used to guide the user to the control that needs correcting by automatically setting its focus.

Server-side Validation By setting a Validator’s EnableClientScript property to false, you can force a post and therefore handle the validation in your server- side script. In the server’s event handler, you can write special validation code in the PreRender event handler. Use the Page object’s Validators collection.

Listing 3.4 ShowValidators.aspx.aspx code

Listing 3.4 ShowValidators.aspx Disabling client-side validation for the validators.

Listing 3.4 ShowValidators.aspx In the Page_PreRender event handler, loop through the page’s validators, check to see if they pass the validation test, and if not manipulate properties of their associated controls.

Listing 3.4 ShowValidators.aspx void Page_PreRender() { foreach (BaseValidator valControl in Page.Validators) { WebControl assControl = (WebControl)Page.FindControl(valControl.ControlToValidate); if (!valControl.IsValid) assControl.BackColor = System.Drawing.Color.Yellow; else assControl.BackColor = System.Drawing.Color.White; } BaseValidator is the root class for all validators. All validators have a ControlToValidate property that has the name of the associated control. Given the name you can get a reference to the control using the FindControl method. This allows you to manipulate the control’s properties. All validators have a boolean IsValid property that indicates whether the validation test succeeds. This can be used to make decisions on what to do with associated controls.

Listing 3.4 ShowValidators.aspx Resulting page if a field is left unfilled.

Listing 3.5 ShowValidationGroups.aspx.aspx code

If you have two submit buttons, you can use the ValidationGroup property to only validate the controls relevant to a button.

Browser’s initial render... Only the controls that are in the button’s ValidationGroup will be validated.

is an HTML element. It renders as a box with a line border surrounding its HTML sub-elements. renders the text that appears in the border of a.

Listing 3.6 ShowDisableValidation.aspx By setting the CausesValidation property to false, you can cause a button click to bypass validation and directly post. Useful for a Cancel button

Listing 3.8 ShowInitialValue.aspx A DropDownList with an associated RequiredFieldValidator. If the control’s current value is equal to the validator’s InitialValue property, the validation test fails. Clicking without selecting Clicking after select

Listing 3.9 ShowRangeValidator.aspx.aspx code

Listing 3.10 ShowDataTypeCheck.aspx.aspx code

Listing 3.11 ShowFixedValue.aspx.aspx code

Listing 3.12 ShowCompareValues.aspx.aspx code

Listing 3.13 ShowRegularExpressionValidator.aspx.aspx code

Listing 3.13 ShowRegularExpressionValidator.aspx Resulting HTML sent to browser. VALID

Browser’s rendering of HTML code.

Listing 3.13 ShowRegularExpressionValidator.aspx Resulting HTML sent to browser. INVALID

Browser’s rendering of HTML code.

Listing 3.14 ShowCustomValidator.aspx.aspx code

Listing 3.14 ShowCustomValidator.aspx Resulting HTML sent to browser. INVALID COMMENT

Browser’s rendering of HTML code.

Listing 3.14 ShowCustomValidator.aspx Resulting HTML sent to browser. VALID COMMENT

Browser’s rendering of HTML code.

Listing 3.16 ShowValidateEmptyText.aspx.aspx code

Listing 3.16 ShowValidateEmptyText.aspx Resulting HTML sent to browser. INVALID PRODUCT CODE

Browser’s rendering of HTML code.

Listing 3.16 ShowValidateEmptyText.aspx Resulting HTML sent to browser. VALID PRODUCT CODE

Browser’s rendering of HTML code.

Listing 3.17 TimedTest.aspx.aspx code

Listing 3.17 TimedTest.aspx Resulting HTML sent to browser. BEFORE SUBMISSION

Browser’s rendering of HTML code.

Listing 3.17 TimedTest.aspx Resulting HTML sent to browser. AFTER SUBMISSION

Browser’s rendering of HTML code.

Listing 3.18 ShowValidationSummary.aspx.aspx code

Listing 3.18 ShowValidationSummary.aspx Resulting HTML sent to browser. BEFORE SUBMISSION

Browser’s rendering of HTML code.

Listing 3.18 ShowValidationSummary.aspx Resulting HTML sent to browser. AFTER SUBMISSION

Browser’s rendering of HTML code.

Listing 3.19 ShowSummaryPopup.aspx.aspx code

Listing 3.19 ShowSummaryPopup.aspx Resulting HTML sent to browser. BEFORE SUBMISSION

Browser’s rendering of HTML code.

Listing 3.21 ShowLengthValidator.aspx.aspx code

Listing 3.21 ShowLengthValidator.aspx Resulting HTML sent to browser. BEFORE SUBMISSION

Browser’s rendering of HTML code.

Listing 3.21 ShowLengthValidator.aspx Resulting HTML sent to browser. AFTER SUBMISSION

Browser’s rendering of HTML code.

Listing 3.24 ShowAjaxValidator.aspx.aspx code

Listing 3.24 ShowAjaxValidator.aspx Resulting HTML sent to browser.

Browser’s rendering of HTML code.