Beginning ASP.NET in C# and VB Chapter 9

Slides:



Advertisements
Similar presentations
1111 Creating ASPX Controls Programatically Objectives You will be able to Dynamically add controls to a page. Dynamically alter properties of controls.
Advertisements

11 Getting Started with ASP.NET Beginning ASP.NET 4.0 in C# 2010 Chapters 5 and 6.
11 ASP.NET Controls II Beginning ASP.NET 4.0 in C# 2010 Chapter 6.
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.
Macros Tutorial Week 20. Objectives By the end of this tutorial you should understand how to: Create macros Assign macros to events Associate macros with.
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
Web Forms. Agenda Web forms Web controls Code separation Dynamic compilation System.Web.UI.Page User controls.
Chapter 9 Web Applications Copyright © 2011 by The McGraw-Hill Companies, Inc. All Rights Reserved. McGraw-Hill.
Chapter 9 – Validating User Input Dr. Stephanos Mavromoustakos.
Tutorial: Introduction to ASP.NET Internet Technologies and Web Application 4 th February 2010.
JavaScript Form Validation
1 CS 3870/CS 5870 Static and Dynamic Web Pages ASP.NET and IIS.
JavaScript & jQuery the missing manual Chapter 11
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.
1 CS 3870/CS 5870 Static and Dynamic Web Pages ASP.NET and IIS.
Chapter 5 Java Script And Forms JavaScript, Third Edition.
1 Web-Enabled Decision Support Systems Introduction to ASP.NET Prof. Name Position (123) University Name.
Chapter 6: Forms JavaScript - Introductory. Previewing the Product Registration Form.
Joe Hummel, PhD Dept of Mathematics and Computer Science Lake Forest College
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.
1 ASP.NET ASP.NET Rina Zviel-Girshin Lecture 3. 2 Overview Cookies Validation controls Client and server side validation Validation control examples.
11 Updating a Database Table Textbook Chapter 14.
Chapter 9 Programming with Web Forms Programming In Visual Basic.NET.
Web Programming: Client/Server Applications Server sends the web pages to the client. –built into Visual Studio for development purposes Client displays.
ASP.NET Web Server Controls Basic Web Server 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.
11 Web Services. 22 Objectives You will be able to Say what a web service is. Write and deploy a simple web service. Test a simple web service. Write.
CSCI 6962: Server-side Design and Programming Introduction to Active Server Pages.
1 Data Bound Controls II Chapter Objectives You will be able to Use a Data Source control to get data from a SQL database and make it available.
McGraw-Hill © 2009 The McGraw-Hill Companies, Inc. All rights reserved. Programming with Visual Web Developer Chapter 9.
C# Tutorial -1 ASP.NET Web Application with Visual Studio 2005.
Microsoft Visual Basic 2005 CHAPTER 7 Creating Web Applications.
Unit 8.3 Learning Objectives Insert users into the ASP.NET Membership system from code Capture data being sent to the database Capture Exceptions that.
1 Chapter 12 – Web Applications 12.1 Programming for the Web, Part I 12.2 Programming for the Web, Part II 12.3 Using Databases in Web Programs.
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.
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.
C# - FCL/Form & Control Validation John Kelleher.
Unit 10 – JavaScript Validation Instructor: Brent Presley.
Mr. Justin “JET” Turner CSCI 3000 – Fall 2015 CRN Section A – TR 9:30-10:45 CRN – Section B – TR 5:30-6:45.
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.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Bookstore Web Application: Client Tier Introducing Web Controls.
11 ASP.NET Server Controls Beginning ASP.NET in C# and VB Chapter 4.
Chapter 27 Getting “Web-ified” (Web Applications) Clearly Visual Basic: Programming with Visual Basic nd Edition.
1111 Creating ASPX Controls Programatically Objectives You will be able to Dynamically add controls to a page. Dynamically alter properties of controls.
11 Getting Started with ASP.NET Beginning ASP.NET in C# and VB Chapters 1 and 2.
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.
Using Personalization Creating user profiles Retrieving, changing, and saving profile properties Using validation controls Using the Forms Designer.
111 State Management Beginning ASP.NET in C# and VB Chapter 4 Pages
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
Unit 27 - Web Server Scripting
12/9/2018 Session 9.1 Calendar and Validation Controls Using Sessions
Static and Dynamic Web Pages
Chapter 3 starting with Chapter 2 detailed concepts
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:

Beginning ASP.NET 4.5.1 in C# and VB Chapter 9 Validation Beginning ASP.NET 4.5.1 in C# and VB Chapter 9

Objectives You will be able to use validation controls on your web pages to validate user inputs automatically.

Validation Controls Validation controls permit declarative validation of user inputs. Specify conditions declaratively rather than writing code to check validity.

Validation Controls Overview RequiredFieldValidator RangeValidator CompareValidator RegularExpressionValidator CustomValidator

Validation Controls Each validation control is bound to a single input control. One input control can have multiple validation controls. Normally an invalid input will prevent the postback from being done. Require user to provide valid inputs before passing them to the server.

CausesValidation Every button has a CausesValidation property. Checked when button is clicked, before page is posted back. If true, validation is performend on all input controls that have validation controls. In the browser. Again on the server. If false, page is posted back without validation.

Why not do validation? Consider a Cancel button. Sometimes we want to be able to do a postback even if some inputs are invalid.

Client-Side Validation ASP.NET transparently provides JavaScript to do validation in the browser. Supported by most modern browsers Chrome Firefox Safari Internet Explorer 5 and later If client-side validation fails, page does not post back. Error information is shown on the page.

Server-Side Validation Even if page passes all validation checks on the browser, inputs will be validated on the server. Hackers can easily bypass client-side validation. Some users may disable JavaScript. Client-side validation is a matter of convenience and performance only. Not security. Server-side code has the ultimate responsibility for ensuring that inputs are valid.

Simple Example Create a new empty ASPX C# website Validation_Demo Add new web form, Default.aspx We will design a page with a TextBox having a range validator. Second TextBox with no validator.

Design the Page Expand the Validation section of the Toolbox. Add a RangeValidator beside the TextBox.

RangeValidator

Display Property Values Static Reserve space on page for the error message even if the control is valid. Dynamic Do not reserve space on page for the error message if the control is valid. Useful when there are mulitple validators for a single control. None Do not display the error message.

Design the Page Add another TextBox with no validator. Just so that we can tab out of the validated input. Add an OK button. btnOK CausesValidation is true by default. Add a label beside the button. lblMessage

The Page in Design View

Add Click Event Handler Double click on the button to add a Click Event Handler.

Page in Source View

Set Breakpoint Set a breakpoint on the Page_Load method. So that we can tell when a postback occurs.

Program Running Enter an invalid number and press tab

Error! Ask google about it

Search Result: Unobtrusive Validation Mode

Search Result: Unobtrusive Validation Mode

Web.config Add Try again.

After User Presses Tab Key Note that the page did not post back.

Server-Side Validation To see how the page will work on a browser that does not support JavaScript set RangeValidator1.EnableClientScript property to false. Try again.

After User Clicks OK Nothing happens when we tab out of the first box. Error message is shown after postback when we click OK.

Server-Side Processing Note that the error message appeared on the page, BUT the click event handler executed even thought the input was invalid. We can prevent the normal click actions if the page is invalid but we have to provide an explicit check.

Server-Side Validity Check protected void btnOK_Click(object sender, EventArgs e) { if (Page.IsValid) lblMessage.Text = "btnOK_Click event handler executed"; } else lblMessage.Text = "Input is invalid"; Try again with invalid input.

Invalid Input

Valid Input

No Input If nothing is entered, the range validation passes. If we want to require input we need another validator. RequiredFieldValidator

Add RequiredFieldValidator

RequiredFieldValidator Properties Try it!

RequiredFieldValidator Click on OK with no inputs.

Validation Summary The validation summary control shows all error messages from the page together in one place. Add a ValidationSummary below the OK button. Modify the error messages to identify the input to which they apply.

Display Options Example: If a validation control’s Text property is set, it will be shown at the position of the validator, and the ErrorMessage will be shown in the Error Summary. Example: Text: "This input is required" ErrorMessage: "First input is required"

RangeValidator

RequiredFieldValidator

Validation Summary Add a ValidationSummary at the bottom of the page.

Validation Summary Try it!

Validation Summary

Summary Only We might want to suppress the error message at the position of the input. Avoid clutter with lots of validated inputs. Set its Display property to None.

Display Property Set To None

Other Display Options If a page has a lot of inputs, we might want to just flag the invalid inputs and put the detailed information in the summary. Example: Flag the input field with an invalid value. Set Text to “*” Set Display back to Static

Flag Invalid Input

Other Display Options

Other Properties of ValidationSummary Border properties DisplayMode HeaderText ShowMessageBox EnableClientScript must be true. ShowSummary Set to false to disable summary

Validation Summary Properties

RangeValidator1

Validation Summary End of Presentation