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.

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.
Adding Controls to User Forms. Adding Controls A user form isn’t much use without some controls We’re going to add controls and write code for them Note.
Microsoft Visual Basic 2005 CHAPTER 8 Using Procedures and Exception Handling.
Visual Basic Fundamental Concepts. Integrated Development Enviroment Generates startup form for new project on which to place controls. Features toolbox.
Tutorial: Introduction to ASP.NET Internet Technologies and Web Application 4 th February 2010.
MIS 3200 – Unit 6.2 Learning Objectives How to move data between pages – Using Query Strings How to control errors on web pages – Using Try-catch.
Microsoft Visual Basic 2012 Using Procedures and Exception Handling CHAPTER SEVEN.
CIS 338: Creating ActiveX Controls Dr. Ralph D. Westfall March, 2003.
ASP.NET Web Application Professor Ralph Westfall May 2011.
Microsoft Visual Basic 2008 CHAPTER 8 Using Procedures and Exception Handling.
INSPIRING CREATIVE AND INNOVATIVE MINDS Module 4: Adding Code to a Microsoft ASP.NET Web Form Implementing Code-Behind Pages Adding Event Procedures to.
08/10/ Iteration Loops For … To … Next. 208/10/2015 Learning Objectives Define a program loop. State when a loop will end. State when the For.
C# Tutorial -1 ASP.NET Web Application with Visual Studio 2005.
1 CS 3870/CS 5870: Note 11 Authentication and Authorization Membership Provider.
Chapter 7 – Navigation Dr. Stephanos Mavromoustakos.
1 CS 3870/CS 5870 Note04 Session Variables and Post Back.
ASP.NET The Clock Project. The ASP.NET Clock Project The ASP.NET Clock Project is the topic of Chapter 23. By completing the clock project, you will learn.
1 CS 3870/CS 5870: Note 13 Lab 6 Authentication and Authorization Roles Management.
1 CS 3870/CS 5870: Note 07 Lab 3 Lab 4 Test 1: Two Tables.
Applications Development
1 CS 3870/CS 5870: Note05 Prog3 Web Application with Database.
CS 101 Test 2 Study Guide Acronyms RAD - Rapid Application Development IDE - Integrated Development Environment GUI - Graphical User Interface VB - Visual.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Bookstore Application: Middle Tier Introducing Code-Behind Files, Session State.
1 CS 3870/CS 5870: Note 19 SiteMap and AJAX Lab 8.
1 CS 3870/CS 5870: Note 20 Web Service. 2 What is Web Service? Providing functionality online to other applications, Web and Windows applications. The.
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.
1 CS 3870/CS 5870: Note 18 SiteMap Prog8. Test 2 50 Points Thursday, Nov 12 2:00 PM – 4:00 PM Lab
Mr. Justin “JET” Turner CSCI 3000 – Fall 2015 CRN Section A – TR 9:30-10:45 CRN – Section B – TR 5:30-6:45.
1 CS387/CS587: Note05 Lab 3. 2 Global.asax Must not be under any sub-folder Application_Start Application_End Application_Error Session_Start Session_End.
1 CS 3870/CS 5870: Note 12 Authentication and Authorization Membership Provider.
1.NET Web Forms ADO.NET Structure © 2002 by Jerry Post.
CONTROL STATEMENTS. A conditional expression uses a comparison operator which results in true or false value. If the comparision is valid it results in.
1 Chapter 4 – Decisions 4.1 Relational and Logical Operators (see other set of slides) 4.2 If Blocks (see other set of slides) 4.3 Select Case Blocks (see.
MIS 3200 – Unit 5.1 Iteration (looping) – while loops – for loops Working with List Items.
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.
1 CS 3870/CS 5870: Note 13 Web Service. 2 What is Web Service? Providing functionality online to other Web applications SOAP Simple Object Access Protocol.
A: A: double “4” A: “34” 4.
1.NET Web Forms Applications: Main Form © 2002 by Jerry Post.
1 CS 3870/CS 5870: Note 14. Prog5 Due 10 PM Wednesday, Oct 21 Authentication and Authorization 2.
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.
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.
11 User Controls Beginning ASP.NET in C# and VB Chapter 8.
Beginning ASP.NET in C# and VB Chapter 9
1 CS 3870/CS 5870: Note 19 AJAX Prog8. Test 2 50 Points Thursday, Nov 12 2:00 PM – 4:00 PM Lab
Computer Science Up Down Controls, Decisions and Random Numbers.
COMPUTER PROGRAMMING I Apply Procedures to Develop List Box and Combo Box Objects.
111 State Management Beginning ASP.NET in C# and VB Chapter 4 Pages
1. Prog3 Try and Catch Testing 2 Catching Database Errors Protected Sub DetailsView1_ItemDeleted( sender As Object, e As DetailsViewDeletedEventArgs)
Visual Basic Fundamental Concepts
CS 3870/CS 5870 Web Service.
A variable is a name for a value stored in memory.
Web Application with Database
CS 3870/CS 5870 Web User Controls.
Session Variables and Post Back
Web Application with Dataase
Using Procedures and Exception Handling
CS 3870/CS 5870 Web User Controls Events (II).
Visual Basic..
CS 3870 Prog5 Shopping Bag.
CS 3870 Web User Control Events.
Static and Dynamic Web Pages
Tonga Institute of Higher Education
Adding Record To Your Database
CS 3870/CS 5870 Test 2 (50 points) Thursday
Web Application with Dataase
MIS 3200 – Unit 5.1 Iteration (looping) Working with List Items
Understanding Buttons and TextBoxes
Overview of the IDE Visual Studio .NET is Microsoft’s Integrated Development Environment (IDE) for creating, running and debugging programs (also.
Presentation transcript:

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 is working Create Prog7 from scratch 2

Prog7/Default.aspx Not inside any sub-folders Based on Prog7MasterPage One message (centered on the page) Use the TreeView to navigate to the pages you want to see. 3

4 Creating ShoppingItem.ascx For page Checkout Add New Items Web User Control File name ShoppingItem.ascx Place code in separate file Different file extension

5 Adding Controls to ShoppingItem.ascx Same as adding to Web Forms Using default setting, not absolute position Textboxes and label on same line

6 Setting Properties of Controls Read Only Width Alignment

7 Class Prog7_ShoppingItem Partial Class Prog7_ShoppingItem Inherits System.Web.UI.UserControl ‘ Private data Private _theID, _theName As String Private _thePrice, _theCost As Double Private _theQuantity As Int32 End Class

8 Public Properties Partial Class Prog7_ShoppingItem Inherits System.Web.UI.UserControl Public Property theID As String Set(value As String) _theID = value End Set Get Return _theID End Get End Property... End Class

9 Public Properties Partial Class Prog7_ShoppingItem Inherits System.Web.UI.UserControl Public Property theQuantity As Integer Set(value As String) _theQuantity = value End Set Get Return _theQuantity End Get End Property... End Class

10 Page Load Event Partial Class Prog7_ShoppingItem Inherits System.Web.UI.UserControl... Protected Sub Page_Load(...) Handles Me.Load lblMsg.Text = “” txtID.Text = _theID txtName.Text = _theName txtPrice.Text = FormatCurrency(_thePrice) txtQuantity.Text = _theQuantity txtCost.Text = FormatCurrency(_theCost) End Sub End Class

Adding Web User Control at Design Time Prog7/Default.aspx Source view (or design view) Drag and Drop ShoppingItem.ascx to Prog7/Default.aspx If error, close and re-open Default.aspx or re-open VS 11

Page Directive Register Prog7/Default.aspx Source view Register Src="~/Prog7/ShoppingItem.ascx" TagPrefix="uc1" TagName="ShoppingItem" %> Use the TreeView to... 12

Page Default.aspx Protected Sub Page_Load(...) Handles Me.Load ShoppingItem.theID = "101" ShoppingItem.theQuantity = 20 End Sub 13

Adding Web User Control at Run Time Must register the control –Drag and Drop or –Copy and Paste Register Src="~/Prog7/ShoppingItem.ascx" TagPrefix="uc1" TagName="ShoppingItem" %> 14

Shopping Bag Could still use DataTable Try SortedList of ShoppingItem 15

Global.asax Session("Prog7_Bag") = New SortedList 16

Page Shopping.aspx Protected Sub btnBag_Click(...) Handles btnBag.Click Dim c1 As Prog7_ShoppingItem Dim bag As SortedList = Session("Prog7_Bag") ‘ Specify file path to load the control ‘ c1 = CType(LoadControl("../ShoppingItem.ascx"), ‘ Prog7_ShoppingItem) c1 = New Prog7_ShoppingItem End Sub 17

Page Shopping.aspx Protected Sub btnBag_Click(...) Handles..... c1 = New Prog7_ShoppingItem c1.theID = txtID.Text c1.theQuantity = txtQuanity.Text... bag.Remove(c1.theID) bag.Add(c1.theID, c1)... End Sub 18

Page Checkout.aspx Protected Sub Page_Load(...) Handles Me.Load Dim c1, c2 As Prog7_ShoppingItem Dim bag As SortedList = Session("Prog7_Bag") ‘ Need to find the form to add the control Dim theForm As Control = Master.Master.FindControl("form1")... theForm.Controls.Add(c1) End Sub 19

Page Checkout.aspx Protected Sub Page_Load(...) Handles Me.Load Dim c1, c2 As Prog7_ShoppingItem... ‘ New does not work c1 = CType(LoadControl("../ShoppingItem.ascx"), Prog7_ShoppingItem) c2 = bag.GetByIndex(0) c1.theID = c2.theID c1.theQuantity = c2.theQuantity theForm.Controls.Add(c1) End Sub 20

Page Checkout.aspx Protected Sub Page_Load(...) Handles Me.Load Dim c1, c2 As Prog7_ShoppingItem... ‘ Must use a loop to add all items in bag For... c1 = CType(LoadControl("../ShoppingItem.ascx"), Prog7_ShoppingItem) c2 = bag.GetByIndex(index) c1.theID = c2.theID c1.theQuantity = c2.theQuantity theForm.Controls.Add(c1) Next End Sub 21

Public Event Define event Raise event Handle event 22

23 Partial Class Prog7_ShoppingItem... Public Event ItemChanged(ByVal x As Lab7_ShoppingItem, ByVal valid As Boolean)... End Class Define Event

24 Partial Class Prog7_ShoppingItem... Protected Sub txtQuantity_TextChanged(…) Handles … If not an integer... RaiseEvent ItemChanged(Me, False) ElseIf negative integer... RaiseEvent ItemChanged(Me, False) Else... RaiseEvent ItemChanged(Me, True) End If End Sub End Class Raise Event

Add Event Handler ‘ Page Checkout Protected Sub Page_Load(...) Handles Me.Load Dim c1, c2 As Prog7_ShoppingItem... c1 = CType(LoadControl("../ShoppingItem.ascx"), Prog7_ShoppingItem) AddHandler c1.ItemChanged, AddressOf HandleChangeEvent theForm.Controls.Add(c1) End Sub 25

Event Handler Private Sub HandleChangeEvent(ByVal Item... )... ‘ Must update Shopping Bag For i = 0 To bag.Count - 1 c2 = bag.GetByIndex(i) If c2.theID = item.theID Then c2.theQuantity = item.theQuantity End If total += c2.theCost Next txtTotal.Text = total... End Sub 26

Using Form to Add Items Protected Sub Page_Load(...) Handles Me.Load Dim c1, c2 As Prog7_ShoppingItem Dim bag As SortedList = Session("Prog7_Bag") ‘ Need to find the form to add the control Dim theForm As Control = Master.Master.FindControl("form1")... theForm.Controls.Add(c1) End Sub 27

Using Panel to Add Items Add Panel1 to Checkout.aspx Protected Sub Page_Load(...) Handles Me.Load Dim c1, c2 As Prog7_ShoppingItem... c1 = CType(LoadControl("../ShoppingItem.ascx"), Prog7_ShoppingItem)... Panel1.Controls.Add(c1)... End Sub 28

Page Shopping.aspx Focus must be correct at all times 29

Fix all errors from earlier Progs! 30

Test 2 Thursday Nov 5 31