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.

Slides:



Advertisements
Similar presentations
1 CS 3870/CS 5870: Lab4 Save with Invalid Price Keep Order After Updating.
Advertisements

Ch. 101 DataTable Data Table Object A DataTable object holds the contents of a table as a rectangular array. A data table is similar to a two-dimensional.
Authenticating Users in an ASP.NET Application. Web Site Administration Tool From VS 2008, click Website/ ASP.Net Configuration to open Web Site Administration.
Working with Session and Application Objects. Postback and Variables Variables declared in a web page including ADO.Net objects may be reinitialized and.
Working with Session. Postback and Variables Variables declared in a web page including ADO.Net objects may be reinitialized and lose their values.
Mark Dixon Page 1 20 – Web applications: Writing data to Databases using ASP.
CIS 270—App Dev II Big Java Chapter 22 Relational Databases.
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.
Chapter 11 Introduction to Database Processing. Class 11: Database Processing Use a Visual Studio Wizard to establish a database connection used to load.
Chapter 10 Managing Data with ASP.NET. ASP.NET 2.0, Third Edition2.
CSCI 6962: Server-side Design and Programming JDBC Database Programming.
Welcome  30 Question & 30 Minutes  Question Will Move Automatically After 1 Min Your Exam Start Now Lecturer : Zalak Thakrar.
Mark Dixon Page 1 23 – Web applications: Writing data to Databases using PhP.
Navigating database with windows forms.. Tiered applications  Provide a means to develop many presentations of the same app  Makes changes to the back.
Session 10: Managing State. Overview State Management Types of State Management Server-Side State Management Client-Side State Management The Global.asax.
© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 Managing State.
© Minder Chen, ASP.NET 2.0: Introduction - 1 ASP.NET 2.0 Minder Chen, Ph.D. Framework Base Class Library ADO.NET: Data & XML.
Mark Dixon 1 22 – Web applications: Writing data to Databases using ASP.Net.
Mark Dixon Page 1 23 – Web applications: Writing data to Databases using ASP.
Lecture Set 14 B new Introduction to Databases - Database Processing: The Connected Model (Using DataReaders)
Needs for Accessing Database To make your web site more dynamic and maintainable, you can display information on your web pages that are retrieved from.
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.
1 OPOL Training (OrderPro Online) Prepared by Christina Van Metre Independent Educational Consultant CTO, Business Development Team © Training Version.
Murach’s ASP.NET 4.0/VB, C1© 2006, Mike Murach & Associates, Inc.Slide 1.
1 CS 3870/CS 5870: Note 11 Authentication and Authorization Membership Provider.
Mark Dixon 1 09 – Java Servlets. Mark Dixon 2 Session Aims & Objectives Aims –To cover a range of web-application design techniques Objectives, by end.
1 CS 3870/CS 5870 Note04 Session Variables and Post Back.
CSCI 6962: Server-side Design and Programming Database Manipulation in ASP.
Introduction to ASP.NET1. 2 Web applications in general Web applications are divided into two parts –The server part –The client part The server part.
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.
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.
Working with the Application Object. Session VS Application Object The Session object helps to preserve data on a per user basis. What if we want to initialize.
Global.asax file. Agenda What is Global.asax file How to add the Global.asax file What are the default events available Explanation to Application_Level.
1 CS 3870/CS 5870: Note 13 Lab 6 Authentication and Authorization Roles Management.
CHAPTER 9 PHP AND MYSQL. A POSSIBLE SITE CONFIGURATION Application Folder index.php includes (folder)header.phpfooter.phpstyle.cssmodel (folder)mysqli_connect.php.
1 CS 3870/CS 5870: Note 07 Lab 3 Lab 4 Test 1: Two Tables.
Module 7: Creating a Microsoft ASP.NET Web Application.
Lecture Set 14 B new Introduction to Databases - Database Processing: The Connected Model (Using DataReaders)
1 CS 3870/CS 5870: Note05 Prog3 Web Application with Database.
Visual Basic.NET Programming March 3, Agenda Questions / Discussion Cookies Project Work (Ends Around 9:00 PM) Demo's (15 minutes per team)
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.
CIS 451: Cookies Dr. Ralph D. Westfall February, 2009.
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 12 Authentication and Authorization Membership Provider.
Working With ASP.NET Application. Create a new virtual directory The procedure to create a new virtual directory Internet Services Manager Right click.
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.
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.
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.
ADO.NET Objects Data Adapters Dr. Ron Eaglin. Agenda Builds on Information in Part I Should have working knowledge of creating a database connection Continuation.
Overview of Previous Lesson(s) Over View  ASP is a technology that enables scripts in web pages to be executed by an Internet server.  ASP.NET is a.
Unit-6 Handling Sessions and Cookies. Concept of Session Session values are store in server side not in user’s machine. A session is available as long.
Chapter 5 Building Your Product Catalog database Objectives Create Database. Create Table. Connect to Database. Use ASP Script to add new products. Use.
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)
CS 3870/CS 5870 Web Service.
Web Application with Database
CS 3870/CS 5870 Web User Controls.
Session Variables and Post Back
Web Application with Dataase
test slide
CS 3870/CS 5870 Web User Controls Events (II).
CS 3870/CS 5870 Test 2 (50 points) Thursday
Working with Session and Application Objects
Presentation transcript:

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

Debugging When an application starts/ends? –Application_Start –Application_End When the session starts/ends? –Session_Start –Session_End 3

Application Start Sub Application_Start(...) DataClass.setupAdapter () End Sub Set up the adapter once for all requests from all users. 4

Lab3/Default.aspx Protected Sub Page_Load(...) Handles Me.Load ‘DataClass.tblProduct.Clear() ‘DataClass.getAllProducts() GridView1.DataSource = DataClass.tblProduct GridView1.DataBind() End Sub Reloading table for every page request. (Could be done in Application_Start) Binding must be done for each page request. 5

SessionStart Sub Session_Start(...) DataClass.getAllProducts() End Sub Refill the data table for each session, 6

Page Updating Textboxes for Individual Fields Binding the textboxes Not binding the textboxes Choosing the way you prefer We discuss the unbinding approach 7

Page Updating Protected Sub Page_Load(…) Handles Me.Load DisplayRow(0) End Sub Private Sub DisplayRow(Index As Integer) Dim row As Data.DataRow row = DataClass.tblProducts.Rows(index) txtID.Text = row(0) txtName.Text = row(1) txtPrice.Text = row(2) End Sub 8

Page Updating Navigation Buttons Partial Class Lab3_Updating Private index As Integer = 0 Protected Sub Button6_Click(…) Handles btnNext.Click index += 1 DisplayRow(index) End Sub Protected Sub Button6_Click(…) Handles btnPrevious.Click index -= 1 DisplayRow(index) End Sub 9

Processing of Dynamic Web Pages Build Web Site: Compiling code-behind classes to a DLL file No exe file ASP.NET instantiates class objects ASP.NET processes the class object ASP.NET generates a page IIS accepts page requests and sends the generated pages back to client 10

Page Updating Navigation Buttons Partial Class Lab3_Updating ‘ Resets index to 0 every time Private index As Integer = 0 Protected Sub Button6_Click(…) Handles btnNext.Click index += 1 DisplayRow(index) End Sub 11

Session Variables Sub Session_Start(...) ‘ productIndex should be better ‘ we need page index later Session(“Index”) = 0 End Sub Protected Sub Page_Load(…) Handles Me.Load DisplayRow(Session(“Index”)) End Sub 12

Navigation Buttons Partial Class Lab3_Updating ‘ Private index As Integer = 0 Protected Sub Button6_Click(…) Handles btnNext.Click Session(“Index”) += 1 DisplayRow(Session(“Index”)) End Sub Protected Sub Button6_Click(…) Handles btnPrevious.Click Session(“Index”) -= 1 DisplayRow(Session(“Index”)) End Sub 13

Enable/Disable Buttons Could make a private Sub 14

Navigation Buttons Partial Class Lab3_Updating ‘ Private index As Integer = 0 Protected Sub Button6_Click(…) Handles btnNext.Click Session(“Index”) += 1 DisplayRow(Session(“Index”)) EnableDisableButtons() End Sub Protected Sub Button6_Click(…) Handles btnPrevious.Click Session(“Index”) -= 1 DisplayRow(Session(“Index”)) EnableDisableButtons() End Sub 15

SQL Statements Update Product Set ProductID = ‘NewID’, ProductName = ‘NewName’, UnitPrice = newPrice Where ProductID = ‘OldID’; Insert Into Product Values(‘NewID’, ‘NewName’, NewPrice); Delete From Product Where ProductID = ‘OldID’; 16

Button Update ‘ allow ID to be modified Protected Sub Button6_Click(…) Handles btnUpdate.Click // ID could be modified Dim Index As Integer = Session(“Index”) Dim oldID As String = DataClass.tblProducts.Rows(Index)(0) Dim newID As String = txtID.Text Dim newName As String Dim newPrice As Double DataClass.UpdateProduct(oldID, newID, newName, newPrice) End Sub 17

UpdateProduct Public Shared Sub UpdateProduct(oldID As String, newID As String, newName As String, newPrice As Double) ‘ Building SQL statement with variables prodCmd.CommandText = "..." con.Open() prodCmd.ExecuteNonQuery() con.Close() End Sub 18

Building SQL Statements With Variables Update Product Set ProductID = ‘NewID’, ProductName = ‘NewName’, Price = newPrice Where ProductID = ‘OldID’; Cmd = "Update Product " & "Set ProductID = '" & NewID & "', " & "ProductName = '" & NewName & "', " & “UnitPrice = " & newPrice & "Where ProductID = '" & OldID & "'" -- No ";" at the end -- need spaces between words 19

Try-Catch Public Shared Sub UpdateProduct(oldID As String, newID As String, newName As String, newPrice As Double) prodCmd.CommandText = "..." Try con.Open() prodCmd.ExecuteNonQuery() con.Close() Catch ex Throw ex End Try End Sub 20

Try-Catch-Finally Public Shared Sub UpdateProduct(oldID As String, newID As String, newName As String, newPrice As Double) prodCmd.CommandText = "..." Try con.Open() prodCmd.ExecuteNonQuery()‘ update database ‘ con.Close() Catch ex Throw new Exception(ex.Message & myCmd.CommandText) Finally con.Close()‘ always close it End Try End Sub 21

Button Update Protected Sub Button6_Click(…) Handles btnUpdate.Click Dim Index As Integer = Session(“Index”) Dim oldID As String = DataClass.tblProduct.Rows(Index)(0) Dim newID As String = txtID.Text Dim oldID As String Dim newPrice As Double Try DataClass.UpdateProduct(oldID, newID, newName, newPrice) ‘ must update tblProducts ‘ order, Session(“index”), DisplayRow Catch ex txtMsg.Text = ex.Message End Try End Sub 22

Product Order Current record still displayed Ascending order of ProductID at all times Update/Insertion/Deletion may change the order Save to database Reload records with “Order By” Update Session(“Index”) Navigation buttons must work correctly 23

Lab3 Should make delete work Try update and new –We will discuss the issues next time 24