ASP.NET Event Handlers Database -> Browser ->Shopping Basket Validators.

Slides:



Advertisements
Similar presentations
Chapter 9 Customizing Data with Web Controls. ASP.NET 2.0, Third Edition2.
Advertisements

Chapter 12: ADO.NET and ASP.NET Programming with Microsoft Visual Basic.NET, Second Edition.
Basics of ASP.NET. 2 © UW Business School, University of Washington 2004 Outline Installing ASP.NET and Web Matrix Data Types Branching Structure Procedures.
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.
ASP.NET Programming with C# and SQL Server First Edition
XP Tutorial 14 New Perspectives on HTML, XHTML, and DHTML, Comprehensive 1 Working with Forms and Regular Expressions Validating a Web Form with JavaScript.
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.
Tutorial 14 Working with Forms and Regular Expressions.
Chapter 6: Forms JavaScript - Introductory. Previewing the Product Registration Form.
Telerik Software Academy ASP.NET Web Forms Data Validation, Data Validators, Validation Groups Telerik Software Academy
1 ASP.NET ASP.NET Rina Zviel-Girshin Lecture 3. 2 Overview Cookies Validation controls Client and server side validation Validation control examples.
Online Shopping JavaScript project for CS 175 JavaScript for Web Development, Spring 2009 By Sita Akella.
The Bean Counter: A JavaScript Program
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.
CIS 375—Web App Dev II ASP.NET 10 Database 2. 2 Introduction to Server-Side Data Server-side data access is unique in that Web pages are basically ___________.
Tutorial 7 Creating Forms. Objectives Session 7.1 – Create an HTML form – Insert fields for text – Add labels for form elements – Create radio buttons.
Lesson 2.  To help ensure accurate data, rules that check entries against specified values can be applied to a field. A validation rule is applied to.
Microsoft Visual Basic 2005 CHAPTER 7 Creating Web Applications.
JavaScript, Fourth Edition Chapter 5 Validating Form Data with JavaScript.
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.
DEV305 Presenting Data with the ASP.NET DataGrid Control Ken Getz Senior Consultant MCW Technologies, LLC.
Working with GridView Control: Adding Columns. Adding Buttons to a Bound GridView: 1. Drag the WebProduct table from Data connection to a page 2. Demo.
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.
Chapter 8 Working With Databases in ASP.NET. Listing 8.1 – ShowListControls Uses The SqlDataSource control for estabishing database connectivity and.
WaveMaker Visual AJAX Studio 4.0 Training Basics: Building Your First Application Binding Basics.
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.
Event JavaScript's interaction with HTML is handled through events that occur when the user or browser manipulates a page. When the page loads, that is.
TRAINING SESSIONS.NET Controls.  Standard Controls  Label  Textbox  Checkbox  Button, Image Button, Image control  Radio Button  Literal  Hyperlink.
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.
CSCI 4230 Homework #3 Group Three Samer Al Jefri * Kevin Odom * David Hood * JD * Phil.
ASP.NET - insert - delete -update DataTables (disconnected datasets) Shopping Basket.
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.
Unit 10 – JavaScript Validation Instructor: Brent Presley.
COMP3241 E-Commerce Technologies Richard Henson University of Worcester November 2014.
Vijayalakshmi G M Validation Controls.
HTML Forms.
CIS 375—Web App Dev II ASP.NET 4 Server Controls.
WaveMaker Visual AJAX Studio 4.0 Training Java Script Events.
Form Validation. Create a form for the user to enter the data seen blow.
XP Tutorial 7 New Perspectives on JavaScript, Comprehensive 1 Working with Forms and Regular Expressions Validating a Web Form with JavaScript.
Text INTRODUCTION TO ASP.NET. InterComm Campaign Guidelines CONFIDENTIAL Simply Server side language Simplified page development model Modular, well-factored,
JavaScript Events Java 4 Understanding Events Events add interactivity between the web page and the user You can think of an event as a trigger that.
Navigation: If the tutorial opens up in your web browser, simply click your mouse to advance to the next slide. Use the “Backspace”
PLACING ORDERS- SHOPPPING CARTS. Introduction There are several stages to the order process, starting with an order page, which allows customers to add.
Beginning ASP.NET in C# and VB Chapter 9
JavaScript Events. Understanding Events Events add interactivity between the web page and the user Events add interactivity between the web page and the.
VOCAB REVIEW. A field that can be computed from other fields Calculated field Click for the answer Next Question.
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.
Validation & Rich Controls
Unit 2 Technology Systems
Coldpruf Online Order Form
COMP3241 E-Commerce Technologies
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
Web Development Using ASP .NET
MIS 3200 – Unit 2.2 Outline What’s the problem with bad data?
Coldpruf Online Order Form
Validation & Rich Controls
Presentation transcript:

ASP.NET Event Handlers Database -> Browser ->Shopping Basket Validators

Event Handlers An Event Handler is a subroutine that executes code for a given event In some cases you know when the event will happen – e.g. Page_Load Most of the time it is user driven – e.g. Button1_Click

Common handlers Onclick Onselect Onselectedindexchanged Onmouseover Onsubmit Can’t cope with overly complex calls

CommandEventArgs This is the key to determining which button was pressed inside an ASP.NET Form Allows you to use the properties CommandArgument CommandName More specialised versions available: DataListCommandEventArgs DataGridCommandEventArgs

Example 1 - In the Web Control

Example 1 - Event Handler Sub CommandButton_Click(sender As Object, e As CommandEventArgs) Select e.CommandName Case "Sort" Sort_List(CType(e.CommandArgument, String)) Case "Submit" Message.Text = "You clicked the Submit button" Case Else Message.Text = "Command name not valid." End Select End Sub

DataGrid CommandEventArgs ItemCommand – Generic event – raised whenever any button associated with an item in the DataGrid is clicked. – provides for programmatically determining which specific command button is clicked and take appropriate action – commonly used to handle custom command buttons for the DataGrid control. DeleteCommand, CancelCommand, EditCommand, UpdateCommand – Events raised whenever the corresponding cancel, delete, edit, or update button associated with an item in the DataGrid is clicked.

Example DataGrid delete event Sub Delete_Item(s As Object, e As DataGridCommandEventArgs ) objDT = Session("Cart") objDT.Rows(e.Item.ItemIndex).Delete() Session("Cart") = objDT End Sub <asp:buttoncolumn buttontype="LinkButton“ commandname="Delete" text="Remove Item" />

Example DataList Event 1 – in the web control NHS No.: Name : <asp:Button ID="btnAdd" runat="server" Text="Add” CommandName="Cart" />

Example DataList event 2 – event handler Sub mypatients_ItemCommand(s As Object, e As DataListCommandEventArgs) Handles mypatients.ItemCommand If e.CommandName = "Cart" Then ‘whole bunch of programming goes here demonstrated later End If End Sub

Database -> DataList -> Shopping Cart 1.Use a SELECT query to retrieve data and bind it to the datalist 2.Put a button in the datalist with CommandName=“Cart” 3.Write an event handler for the datalist – Takes information from the list – Puts information into new row of table stored in Session

Event handler for datalist Sub mypatients_ItemCommand(s As Object, e As DataListCommandEventArgs) Handles mypatients.ItemCommand If e.CommandName = "Cart" Then NOW WE WRITE THIS BIT End If End Sub

If CommandName=“Cart” 1.Retrieve the shopping cart from the session 2.Create a new row 3.Retrieve information from the relevant row of the datalist 4.Put the information from the datalist into the new row 5.Put the new row on the bottom of the cart table 6.Put the table back into the session This is the only new bit you have not seen before

– Displays on screen, but can’t be used programmatically <asp:Label id=“stuff” text=‘ ’ Runat=“server” /> – Now the info from the container is associated with an object that has an ID that we can use, e.g: stuff.Text

3 – retrieve data from relevant row of datalist If e.CommandName = "Cart" Then Dim temp as Label = e.Item.FindControl(“stuff") Dim quantity As TextBox = e.Item.FindControl(“amount”) End If So you put temp.Text and quantity.Text into the new row for the shopping cart

Explanation of code for step 3 e – DataListCommandEventArg that we passed in – Essentially all the objects from the row of the datalist that was clicked on e.Item – Used to address a specific object in the EventArgs e.Item.FindControl – Used to find a specific NAMED object in the EventArgs. In this case a specific label & a specific textbox

Images in the DataList <asp:Image ID=“mugshot” runat=“server” ImageUrl=' ‘ > Where P_Picture is a column in the table that contains the filename for the picture e.g. pic1.jpg

Compares the value of one input to another input or to a fixed value If the input is empty, the validation will succeed – You need to make the field required to solve this problem Compare Validator

Example Comparison Validation Enter your password: <asp:CompareValidator id="compval" Display="dynamic" ControlToValidate="txt1" ControlToCompare="txt2" ForeColor="red“BackColor="yellow" Type="String" EnableClientScript="false" Text="Validation Failed!" runat="server" />

Output

Range Validation Checks that the user enters a value that falls between two values Ranges can be within numbers, dates, or characters. Does not fail if the input is empty. – Solve this by making the input required Does not fail if the input value cannot be converted to the data type specified. – Combine with CompareValidator to solve this

Example Range Validation Enter a grade from 1 to 20: <asp:RangeValidator ControlToValidate="tbox1" MinimumValue="1“ MaximumValue=“20" Type="Integer“ EnableClientScript="false" Text="The value must be from 1 to 20" runat="server" />

Output

Regular Expression Validator Ensures that the value of an input matches a specified pattern Does not fail if the input is empty – Make the input required to solve this

Example Regular Expression Validation Enter your credit card number: <asp:RegularExpressionValidator id=“REV1" runat="server“ EnableClientScript="false" ControlToValidate="txtbox1" ErrorMessage="The card number must be 16 digits long" ValidationExpression="\d{16}“ />

Output

Required Field Validator Ensures user has input some data Leading and trailing spaces of the input value are removed before validation.

Example Required field validation Name: <asp:RequiredFieldValidator id="RFV1" runat="server" Text="Your address is required" ControlToValidate=" “ />

Output

Alternative Output

Other Validation Controls ValidationSummary – Displays a report of all validation errors occurred in a Web page CustomValidator – Write your own

Examples Code demonstrated in lecture will go on the ASP.NET section of the discussion board fvalidationcontrols.asp

TO DO Oasisplus – Shopping Basket Activity – Coursework NEXT WEEK – JavaScript