CS 3870 Web User Control Events.

Slides:



Advertisements
Similar presentations
Unit 02. ASP.NET Introduction HTML & Server controls Postbacks Page Lifecycle.
Advertisements

1 CS 3870/CS 5870: Lab4 Save with Invalid Price Keep Order After Updating.
11 User Controls II Chapter Objectives You will be able to Create a realistic reusable user control. Use data binding in a user control. Change.
11 ASP.NET Controls II Beginning ASP.NET 4.0 in C# 2010 Chapter 6.
Fixing Broken Programs. How do you figure out what’s wrong? Look carefully at the error message. Locate the error – Most messages have line numbers –
Tutorial: Introduction to ASP.NET Internet Technologies and Web Application 4 th February 2010.
Online Shopping JavaScript project for CS 175 JavaScript for Web Development, Spring 2009 By Sita Akella.
11 Updating a Database Table Textbook Chapter 14.
ASP Hello, world. ServerClient Response Request A form.
ITS 328 CHAPTER 3: STORING DATA IN MEMORY 1. Storing Data in Memory After today you will be able to: ◦Explain how a DataTable stores data ◦Add new data.
Internet Technologies and Web Application Web Services With ASP.NET Tutorial: Introduction to.
1 CS 3870/CS 5870: Note 11 Authentication and Authorization Membership Provider.
11 Using ADO.NET II Textbook Chapter Getting Started Last class we started a simple example of using ADO.NET operations to access the Addresses.
1 CS 3870/CS 5870 Note04 Session Variables and Post Back.
1 Chapter Eleven Handling Events. 2 Objectives Learn about delegates How to create composed delegates How to handle events How to use the built-in EventHandler.
© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 Unit 3: Adding Code to a Microsoft ASP.NET Web Form.
Dynamic Dropdown Lists 1. Objectives You will be able to Use Dropdown Lists to solicit multiple choice user input in an ASPX web page. Populate a Dropdown.
Rules Two Teams Questions worth 1-3 points – Entire team can confer to answer the question – Max of 2 minutes per question – You can use a computer on.
CS0004: Introduction to Programming Project 1 – Lessons Learned.
6c – Function Procedures Lingma Acheson Department of Computer and Information Science, IUPUI CSCI N331 VB.NET Programming.
CSCI 6962: Server-side Design and Programming JSF DataTables and Shopping Carts.
1 CS387/CS587: Note 08 Shopping Bag DataTable. 2 DataClass Public Shared Function NewShoppingBag() As Data.DataTable Dim bag As New Data.DataTable bag.Columns.Add("Product.
C# - FCL/Form & Control Validation John Kelleher.
1 CS 3870/CS 5870: Note 12 Authentication and Authorization Membership Provider.
From C++ to C# Part 5. Enums Similar to C++ Similar to C++ Read up section 1.10 of Spec. Read up section 1.10 of Spec.
MIS 3200 – Unit 3.2 Page_Load method AutoPostBack property of controls IsPostBack method of the Page object Understanding web page life cycle.
1 CS 3870/CS 5870: Note 16 Web User Controls. Prog 7 Copy Prog6 to Prog7 Modify all files for Prog7 Remove Web.config from sub-folders Make sure Prog7.
Architecture Multi Layered Architecture (n-tier): Application: Model Controllers Database Access Graphical User Interface (GUI): Forms, components, controls.
1 CS387/CS587: Note04 Lab 3. 2 Master Page All Web pages will be similar Should be created before other web pages Add New Items Controls on the Master.
CSCI 4230 Homework #3 Group Three Samer Al Jefri * Kevin Odom * David Hood * JD Wells * Philippe Gambling.
Objects and Classes Engineering 1D04, Teaching Session 9.
A: A: double “4” A: “34” 4.
1 CS 3870/CS 5870: Note07 Prog 4. Master Pages Creating a master page based on another master page MainMasterPage –For all Progs and Tests Prog4MasterPage.
1111 Creating ASPX Controls Programatically Objectives You will be able to Dynamically add controls to a page. Dynamically alter properties of controls.
Lecture Set 7 Procedures and Event Handlers Part B - The Structure of an Application Event Handlers.
Graphical User Interface Components Version 1.1. Obectives Students should understand how to use these basic Form components to create a Graphical User.
Event Handling & Viewstate CS 351 Ed Gellenbeck. Today Review of Web Forms ASP.NET Object Hierarchy Events State Management Page State Session State Application.
1 Working with Controls at Run Time. 2 Objectives You will be able to Add controls to a Windows form at run time. Modify controls at run time.
Beginning ASP.NET in C# and VB Chapter 9
These materials where developed by Martin Schray. Please feel free to use and modify them for non-commercial purposes. If you find them useful or would.
COMPUTER PROGRAMMING I Apply Procedures to Develop List Box and Combo Box Objects.
Validation & Rich Controls
Chapter 9 Programming Based on Events
A variable is a name for a value stored in memory.
INF230 Basics in C# Programming
Computing with C# and the .NET Framework
CS 3870/CS 5870 Web User Controls.
Session Variables and Post Back
Security Basics and ASP.NET Support
Chapter Eleven Handling Events.
Web Application with Dataase
Windows Desktop Applications
CS 3870 Prog6 Roles Management Due Monday, November 5 Group Assignment.
CHAPTER FIVE Decision Structures.
Decision Structure - 1 ISYS 350.
CS 3870/CS 5870 Web User Controls Events (II).
Review Operation Bingo
Visual Basic..
CS 3870 Prog5 Shopping Bag.
Delegates & Events 1.
CIS16 Application Development and Programming using Visual Basic.net
Self Study GUI Properties & Events
Static and Dynamic Web Pages
Additional Topics in VB.NET
CS 3870/CS 5870 Test 2 (50 points) Thursday
Web Application with Dataase
5/6/2019 Session 8.2 Postback, ViewState
label1 Name label2 Time (0-23) textBox1 textBox2 textBox3 button1
Validation & Rich Controls
Poker2.jpg Poker14.jpg int num1, num2;
Presentation transcript:

CS 3870 Web User Control Events

Adding Items to Shopping Bag DataTable bag = (DataTable)Session["Prog7_Bag"]; DataRow row = bag.NewRow(); row[0] = txtID.Text; row[1] = txtName.Text; row[2] = txtQuantity.Text; //row[3] = txtPrice.Text; //row[4] = txtSubTotal.Text; row[3] = double.Parse(txtPrice.Text.Replace("$", "")); row[4] = double.Parse(txtSubTotal.Text.Replace("$", ""));

Public Event Define event Raise event Handle event

TextChanged for txtQuantity TextChanged event is defined by for txtQuantity Raised when the text changed We only need to handle it Inside Class Prog7_ShoppingItem AutoPostBack to True

TextChanged for txtQuantity protected void txtQuantity_TextChanged(object sender, EventArgs e) { int quantity; if(int.TryParse(txtQuantity.Text, out quantity) && quantity >= 0) // update the object and display new cost _theQuantity = quantity; _theCost = _theQuantity * _thePrice; lblMsg.Text = ""; txtCost.Text = string.Format("{0:C}", _theCost); } else // Error message on label and clear Cost txtCost.Text = “” lblMessage.Text = “Invalid”

Checkout.aspx The total cost not updated when one ShoppingItem has changed. We need an event!

Define Event VB.NET Public Event ItemChanged(ByVal x As Prog7_ShoppingItem, ByVal valid As Boolean) C# //Declaration of delegate. public delegate void ItemChangedHandler(Prog7_ShoppingItem x, bool valid); //Instance of delegate used in declaring event. public event ItemChangedHandler ItemChanged;

Raise Event protected void txtQuantity_TextChanged(. . .) { int quantity; if(int.TryParse(txtQuantity.Text, out quantity) && quantity >= 0) // update the object and display new cost ItemChanged(this, true); } else // Error message on label and clear Cost ItemChanged(this, false);

Event Handler //Handler for an item quantity changing. private void HandleChangeEvent(Prog7_ShoppingItem x, bool valid) { if(valid) } else txtTotal.Text = "";

private void HandleChangeEvent(Prog7_ShoppingItem x, bool valid) { if (valid) DataTable theTable = (DataTable)Session["Prog5_Bag"]; double total = 0; DataRow row; for (int i = 0; i < theTable.Rows.Count; i++) row = theTable.Rows[i]; if (row[0].ToString() == x.TheID) row[2] = x.TheQuantity; row[4] = x.TheCost; } total += double.Parse(row[4].ToString()); txtTotal.Text = string.Format("{0:C}", total); else txtTotal.Text = "";

Add Event Handler // Page Checkout protected void Page_Load(object sender, EventArgs e) { for (int i = 0; i < theTable.Rows.Count; i ++) . . . item.ItemChanged += HandleChangeEvent; Panel1.Controls.Add(item); }

Page Shopping.aspx Focus must be correct at all times