Validation & Rich Controls

Slides:



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

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.
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
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
Database-Driven Web Sites, Second Edition1 Chapter 8 Processing ASP.NET Web Forms and Working With Server Controls.
Module 7: Validating User Input.
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.
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.
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.
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.
ASP.NET Event Handlers Database -> Browser ->Shopping Basket Validators.
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.
VALIDATION CONTROLS.  Validation Controls are primarily used to validate, or verify the data entered by user into a web form.  Validation controls attempt.
1 Final Review. 2 Final Exam  30% of your grade for the course  December 9 at 7:00 p.m., the regular class time  No makeup exam or alternate times.
Building Applications using ASP.NET and C# / Session 4 / 1 of 15 Session 4.
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.
Vijayalakshmi G M Validation Controls.
1111 Creating ASPX Controls Programatically Objectives You will be able to Dynamically add controls to a page. Dynamically alter properties of controls.
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.
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.
ASP.NET Programming with C# and SQL Server First Edition
JavaScript, Sixth Edition
Chapter 5 Validating Form Data with JavaScript
Y.-H. Chen International College Ming-Chuan University Fall, 2004
Computing with C# and the .NET Framework
Validation Controls, User Controls, Master Pages
A variable is a name for a value stored in memory.
In this session, you will learn to:
Decision Structure - 1 ISYS 350.
Web Application Web Application are programs that can be executed either on a Web server or in a Web browser. An Online store accessed through a browser.
Security Basics and ASP.NET Support
Data Virtualization Tutorial… CORS and CIS
CHAPTER FIVE Decision Structures.
Web Programming– UFCFB Lecture 17
Working with Forms and Regular Expressions
Unit 27 - Web Server Scripting
CHAPTER FIVE Decision Structures.
MIS 3200 – Unit 4 Complex Conditional Statements else if switch.
Decision Structure - 1 ISYS 350.
Tutorial 12 – Security Panel Application Introducing the Select Case Multiple-Selection Statement Outline Test-Driving the Security Panel Application.
Part A – Doing Your Own Input Validation with Simple VB Tools
12/9/2018 Session 9.1 Calendar and Validation Controls Using Sessions
Decision Structures ISYS 350.
JavaScript Form Validation
Static and Dynamic Web Pages
Decision Structure - 1 ISYS 350.
Additional Topics in VB.NET
Web Development Using ASP .NET
Decision Structure - 1 ISYS 350.
5/6/2019 Session 8.2 Postback, ViewState
MIS 3200 – Unit 2.2 Outline What’s the problem with bad data?
Programming with Microsoft Visual Basic 2008 Fourth Edition
Server Controls Validation Controls
.NET Validation Controls
Validation & Rich Controls
Presentation transcript:

Validation & Rich Controls ITEC 420 Framework Based Internet Applications Validation & Rich Controls

- Users might ignore an important field. Validation Why we need Validation ? - Users might ignore an important field. - Users might try to type short string of nonsense to circumvent a required field (like e-mail). - Users might make an honest mistake, such as entering a typing error, entering a non-numeric character in numeric field. - Malicious users might try to exploit a weakness in your code by entering carefully structured wrong values (like sql injection).

Validator Controls Asp.NET provides five validator controls. Four of these are tagetted at specific types of validation, while the fifth allows you to apply custom validation routines. Each validation control can be bound to a single input control. In addition, you can apply more than one validation control to the same input control to provide multiple types of validation.

Validation Controls Behaviour RangeValidator, Compare Validator and RegularExpressionValidator, validations will automatically succeed if the input control is empty due to the lack of value to validate. If that is not the behaviour you want, you should also add a Required field validator and link to the same input control.

Server Side Validation & Client Side Validation When a user clicks a button to submit submit the page depending on the buttons CausesValidation property, which can be set to True or False. If True (default one): ASP.NET will automatically validate the page when user clicks the button. It does this by performing the validation for each control on the page. If any control fails to validate, ASP.NET will return the page with some error information,depending on your settings. Click event-code may or may not be executed. - You have to specifically check in the event handler whether the page is valid (p.s. Page.IsValid) In most modern browsers ASP.NET automatically adds JavaScript code for client-side validation. In this case as guessed without informing the server validation takes place on client side. Even if the page validates successfully on client-side, ASP.NET revalidates it when it is received at the server. (Due to the possibility of hacking javascript) ASP.NET remains secure via double validation.

Found in System.Web.UI.WebControls namespace. Validation Controls Found in System.Web.UI.WebControls namespace. Key properties could be listed as

Validation Controls Each validator has some specific properties which must be taken into account inoerder to validate an input. Below table lists these properties.

Set RangeValidator so that an integer from 1 to 10 will be valid. Sample Validation Create a form with two textboxes, one button, a label control (to prove button is clicked) and a RangeValidator. Set RangeValidator so that an integer from 1 to 10 will be valid. Button has CausesValidation property set to true by default. ASP.NET handles lost focus event, when the textbox looses focus if validation fails error message will be displayed in most browsers. Problem is that: click-event will be executed, even the page is invalid. To fix such problem use on buttons click (In this sample)==> if (!RangeValidator.IsValid) return; // if we have a single validator Otherwise İf (!Page.IsValid) return;

Place the codes below to their appropriate addresses Sample Validation Place the codes below to their appropriate addresses A number (1 to 10): <asp:TextBox id="txtValidated" runat="server" /> <asp:RangeValidator id="RangeValidator" runat="server" ErrorMessage="This Number Is Not In The Range" ControlToValidate="txtValidated" MaximumValue="10" MinimumValue="1" Type="Integer" /> <br /><br /> Not validated: <asp:TextBox id="txtNotValidated" runat="server" /><br /><br /> <asp:Button id="cmdOK" runat="server" Text="OK" OnClick="cmdOK_Click" /> <asp:Label id="lblMessage" runat="server" EnableViewState="False" /> Finally, here is the code that responds to the button click: protected void cmdOK_Click(Object sender, EventArgs e) { if (!Page.IsValid) return; lblMessage.Text = "cmdOK_Click event handler executed."; }

Another Sample Validation Sometimes you have a carefully designed and created web page so you are looking for another space to display validation messages. In such cases the following method may help (validation summary control): From the previous sample set the Display property of the Range Validator control to none. Add a validation summary to a suitable location. In any case, the validation summary will display even if you did not update the display property, this control is able to collect and display all error messages in case of an invalid input. If you set the text property of Range Validator control to * and error message to an detailed message and if you set display property to static or dynamic and have a validation summary. Then validation summary will display the error message while range validator displaying the *. Also HeaderText property of Validation control could be used to display a specialized title. DisplayMode property of Validation control could be arranged to displays error as bulletlist,List and Single paragraph. Using Showsummary property as false and setting Showmessagebox to true will force the error messages to be displayed in a dialog box.

You can create manual validation in one of three ways This sample uses the 2nd technique: protected void cmdOK_Click(Object sender, EventArgs e) { string errorMessage = "<b>Mistakes found:</b><br />"; // Search through the validation controls. foreach (BaseValidator ctrl in this.Validators) if (!ctrl.IsValid) errorMessage += ctrl.ErrorMessage + "<br />"; // Find the corresponding input control, and change // the generic Control variable into a TextBox // variable. // This allows access to the Text property. TextBox ctrlInput = (TextBox)this.FindControl(ctrl.ControlToValidate); errorMessage += " * Problem is with this input: "; errorMessage += ctrlInput.Text + "<br />"; } lblMessage.Text = errorMessage; You can create manual validation in one of three ways Use your own code to verify the values. (not using validation controls) Disable the EnableClientScript property for each validation control. This allows an ivalid page to be submitted. Set buttons CausesValidation to false. Then you have to validate the page manually using Page.Validate() method. Then examine the IsValid property or properties, and decide what to do. To validate regular expressions check page 343 from «Beginning ASP.NET 3.5 in C# 2008, From Novice to Professional». For custom validators ServerValidate event is the one which must be handled check page 350.

Custom Validation Sample protected void vldCode_ServerValidate(Object source, ServerValidateEventArgs args) { try // Check whether the first three digits are divisible by seven. int val = Int32.Parse(args.Value.Substring(0, 3)); if (val % 7 == 0) args.IsValid = true; } else args.IsValid = false; catch // An error occurred in the conversion. // The value is not valid. protected void cmdSubmit_Click(Object sender, EventArgs e) if (Page.IsValid) lblMessage.Text = "This is a valid form.";

Validation Groups In more complex pages, you might have several distinct groups of controls, possibly in separate panels. In these situations, you may want to perform validation separately. For example, you might create a form that includes a box with login controls and a box underneath it with the controls for registering a new user. Each box includes its own submit button, and depending on which button is clicked, you want to perform the validation just for that section of the page. This scenario is possible thanks to a feature called validation groups. To create a validation group, you need to put the input controls, the validators, and the CausesValidation button controls into the same logical group. You do this by setting the ValidationGroup property of every control with the same descriptive string (such as “LoginGroup” or “NewUserGroup”). Every control that provides a CausesValidation property also includes the ValidationGroup property.