COMP3121 E-Business Technologies Richard Henson University of Worcester November 2011.

Slides:



Advertisements
Similar presentations
Lecture 6/2/12. Forms and PHP The PHP $_GET and $_POST variables are used to retrieve information from forms, like user input When dealing with HTML forms.
Advertisements

Tutorial 6 Creating a Web Form
Languages for Dynamic Web Documents
Copyright 2004 Monash University IMS5401 Web-based Systems Development Topic 2: Elements of the Web (g) Interactivity.
1 Chapter 12 Working With Access 2000 on the Internet.
Web Development Using ASP.NET CA – 240 Kashif Jalal Welcome to week – 1.1 of…
Tutorial 6 Working with Web Forms
COMP3121 E-Business Technologies Richard Henson University of Worcester November 2010.
ASP.NET Programming with C# and SQL Server First Edition
Tutorial 6 Working with Web Forms. XP Objectives Explore how Web forms interact with Web servers Create form elements Create field sets and legends Create.
Chapter 7 Managing Data Sources. ASP.NET 2.0, Third Edition2.
Computer Science 101 Web Access to Databases Overview of Web Access to Databases.
2440: 141 Web Site Administration Web Server-Side Programming Professor: Enoch E. Damson.
Chapter 9 Collecting Data with Forms. A form on a web page consists of form objects such as text boxes or radio buttons into which users type information.
DAT602 Database Application Development Lecture 15 Java Server Pages Part 1.
1 Web Developer & Design Foundations with XHTML Chapter 6 Key Concepts.
INTRODUCTION TO WEB DATABASE PROGRAMMING
9-1 aslkjdhfalskhjfgalsdkfhalskdhjfglaskdhjflaskdhjfglaksjdhflakshflaksdhjfglaksjhflaksjhf.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
Reading Data in Web Pages tMyn1 Reading Data in Web Pages A very common application of PHP is to have an HTML form gather information from a website's.
XP Tutorial 6New Perspectives on HTML and XHTML, Comprehensive 1 Creating Web Page Forms Designing a Product Registration Form Tutorial 6.
CSCI 6962: Server-side Design and Programming Course Introduction and Overview.
Architecture Of ASP.NET. What is ASP?  Server-side scripting technology.  Files containing HTML and scripting code.  Access via HTTP requests.  Scripting.
JavaScript & jQuery the missing manual Chapter 11
CIS 375—Web App Dev II ASP.NET 2 Introducing Web Forms.
Introduction to ASP.NET. Prehistory of ASP.NET Original Internet – text based WWW – static graphical content  HTML (client-side) Need for interactive.
Dr. Azeddine Chikh IS444: Modern tools for applications development.
Object-Oriented Application Development Using VB.NET 1 Chapter 12 Web Forms, HTML, and ASP.NET.
An Introduction to ASP.NET Ed Dunhill blogs.msdn.com/edunhill SLIDE7.
Server-side Scripting Powering the webs favourite services.
COMP3121 E-Business Technologies Richard Henson University of Worcester November 2009.
Overview of Previous Lesson(s) Over View  ASP.NET Pages  Modular in nature and divided into the core sections  Page directives  Code Section  Page.
© 2008 Dr. Paul Walcott – The University of the West Indies: Cave Hill CampusDr. Paul Walcott COMP6325 Advanced Web Technologies Dr. Paul Walcott The University.
COMP3241 E-Commerce Technologies Richard Henson University of Worcester October 2012.
1 PHP and MySQL. 2 Topics  Querying Data with PHP  User-Driven Querying  Writing Data with PHP and MySQL PHP and MySQL.
CNIT 133 Interactive Web Pags – JavaScript and AJAX JavaScript Environment.
Web Programming: Client/Server Applications Server sends the web pages to the client. –built into Visual Studio for development purposes Client displays.
© Minder Chen, ASP.NET 2.0: Introduction - 1 ASP.NET 2.0 Minder Chen, Ph.D. Framework Base Class Library ADO.NET: Data & XML.
9 Chapter Nine Compiled Web Server Programs. 9 Chapter Objectives Learn about Common Gateway Interface (CGI) Create CGI programs that generate dynamic.
Client Scripting1 Internet Systems Design. Client Scripting2 n “A scripting language is a programming language that is used to manipulate, customize,
1 In the good old days... Years ago… the WWW was made up of (mostly) static documents. –Each URL corresponded to a single file stored on some hard disk.
ASP.NET application. Roadmap ASP.NET file types Bin directory Application updates Simple application from start to finish using a virtual directory Behind.
McGraw-Hill © 2009 The McGraw-Hill Companies, Inc. All rights reserved. Programming with Visual Web Developer Chapter 9.
COMP3121 E-Commerce Technologies Richard Henson University of Worcester November 2011.
COMP3241 E-Commerce Technologies Richard Henson University of Worcester October 2014.
Murach’s ASP.NET 4.0/VB, C1© 2006, Mike Murach & Associates, Inc.Slide 1.
Creating Dynamic Web Pages Using PHP and MySQL CS 320.
Chapter 8 Collecting Data with Forms. Chapter 8 Lessons Introduction 1.Plan and create a form 2.Edit and format a form 3.Work with form objects 4.Test.
CSCI 6962: Server-side Design and Programming Database Manipulation in ASP.
COMP3241 E-Business Technologies Richard Henson University of Worcester October 2012.
Introducing ASP.NET 2.0. Internet Technologies WWW Architecture Web Server Client Server Request Response Network HTTP TCP/IP PC/Mac/Unix + Browser (IE,
1 MSCS 237 Overview of web technologies (A specific type of distributed systems)
VITALE, CATURANO & COMPANY LTD Microsoft SharePoint Web Part Development Overview VITALE, CATURANO & COMPANY LTD SharePoint Developer Series – Web Part.
Introduction to JavaScript CS101 Introduction to Computing.
Christopher M. Pascucci.NET Programming CodeBehind.
ASP.NET in Definition: 1.ASP.NET is a web application framework developed and marketed by Microsoft to allow programmers to build dynamic web sites,
The Problem of State. We will look at… Sometimes web development is just plain weird! Internet / World Wide Web Aspects of their operation The role of.
BlackBerry Applications using Microsoft Visual Studio and Database Handling.
ASP.NET (Active Server Page) SNU OOPSLA Lab. October 2005.
COMP3241 E-Commerce Technologies Richard Henson University of Worcester November 2014.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
ASP-2-1 SERVER AND CLIENT SIDE SCRITPING Colorado Technical University IT420 Tim Peterson.
111 State Management Beginning ASP.NET in C# and VB Chapter 4 Pages
Chapter 1 Getting Started with ASP.NET Objectives Why ASP? To get familiar with our IDE (Integrated Development Environment ), Visual Studio. Understand.
ASP.NET Forms.
COMP3241 E-Commerce Technologies
Haritha Dasari Josue Balandrano Coronel -
PHP / MySQL Introduction
Chapter 23 – ASP.NET Outline 23.1 Introduction NET Overview
Presentation transcript:

COMP3121 E-Business Technologies Richard Henson University of Worcester November 2011

Week 6: Database Design, Server Scripting and Forms Design for Shopping Cart Systems n Objectives:  Explain the.net coding required to trap data from HTML forms and write data to specified data fields  Explain the use of asp.net web controls with HTML to allow parameter passing between pages  Create a shopping cart  Link a shopping cart with product pages for the transfer and storage of shopping data

HTML forms and Web forms n HTML forms work at the client end…  collect data in a structured way  store it as pre-defined data type with specific field name, initially on the local machine n Web forms are asp.net constructs  easily created in Visual Studio using.net toolbox  don’t use HTML… in this module we’ll be sticking with HTML forms

Care with mapping of data within a HTML form n Structure of a HTML form:  Get/Post tell page where to send the data  text boxes/fieldnames for adding data  button(s) to trigger the sending of data to the location specified by get or post… n Data added to the form can be sent to:  address  URL of a web server

HTML forms Input-Output syntax n Basic structure: … n Basic structure: … n Within the form definition, ACTIONpoints to a URL that will accept the supplied information and do something with it n Within the form definition, ACTION points to a URL that will accept the supplied information and do something with it  it is up to the web server at that website to deduce the type of script from its suffix  the web server then needs to use appropriate software to process it

HTML forms Input-Output syntax n Also within the form definition, METHODtells the form how to send its data fields back to the script: n Also within the form definition, METHOD tells the form how to send its data fields back to the script:  POST sends all the information from the form separately from the URL string »could be used with mailto  GET attaches the information from the form to the end of the URL string (max 255 characters)

Modular Development of Applications: “code” files in HTML n Existing good code recycled whenever possible…  useful for portability (no point in rewriting…) n Several ways to use settings/code text file called within first.aspx page:  SSI Include global.asax  “code behind” css n Also possible to associate “ready to run” compiled code  “toolbox” controls & “assemblies”

The Server-Side #Include (SSI) Directive n Saved as a.inc file  used with multiple asp(x) pages n Syntax: »#INCLUDE directive and either “VIRTUAL” or “FILE” keyword placed inside what would normally be HTML comment tags, with file=“filename” »e.g: »e.g:

C# “classes” and the Code Behind model n When a.aspx page is requested and renders markup to a browser…  ASP.NET generates & compiles the “classes” that actually perform the tasks required to run the page  the.net framework sets up the JIT run-time environment, and converts code to “intermediate language” (IL) n This means that the code that runs is not solely the code that was created for the.aspx page and its associated “code behind” (!)

“Classes” and the Code Behind model

Generating and Running the Page Class Code n When the.aspx page runs, it has combined:  the server-side elements in the page »e.g. toolbox controls  the event-handling code written as “code behind” n The class or classes that the compiler creates depends on whether the page uses the single-file model or the code-behind model  no need to pre-compile such pages into assemblies!

Generating and Running the Page’s “Class” Code n.NET framework dynamically compiles & runs.aspx pages the first time user requests them:  IF…any changes are subsequently made »either to the page »or resources the page depends on  THEN… the page is automatically recompiled n.NET also supports precompilation of a Web site:  to enhance performance  to perform error checking  to support site deployment

Single-File Pages n When the page is compiled:  the compiler: »generates then… »compiles  EITHER »a new class that derives from the base Page class  OR »a custom base class defined with the Inherits attribute of Page directive.

Single-File Pages  Example: »when a new ASP.NET Web page named SamplePage1 is created in application root directory »then a new class named ASP.SamplePage1_aspx will be derived from the Page class

Single-File Pages n IF single-file is inside an application subfolder  subfolder name is used as part of the generated class »contains declarations for the controls in the.aspx page »contains the event handlers and other custom code

After Page generation… n Generated class…  compiled into an assembly  assembly loaded into the application domain n Page class…  Instantiated  executed  renders output to the browser…

Effect of Page modifications n IF page changes & would affect the generated class… e.g.  adding controls  modifying code n THEN »compiled class code is invalidated »a new class is generated

Using C# classes with “event- driven” controls EXAMPLE (an “add to cart” button): protected void DataList1_ItemCommand(objectsource, DataListCommandEventArgs e) { if (e.CommandName == "AddToCart") { // Add code here to add the item to the shopping cart. // Use the value of e.Item.ItemIndex to retrieve the data // item in the control. }}

The “global.asax” An optional way of including otherwise unlisted events, objects, with application aspx scripts An optional way of including otherwise unlisted events, objects, with application aspx scripts  normally placed in root folder n.NET is configured so that any direct URL request for global.asax automatically rejected n.NET is configured so that any direct URL request for global.asax automatically rejected »external users therefore cannot download or view the code in it »makes the settings very secure… n Parsed & compiled at run time nParsed & compiled at run time dynamically generated.NET class (HttpApplication)

Use of Multiple Scripting languages n n General rule… DON’T!   use of multiple compilers wastes system resources n n If you must:   HTML tag and its LANGUAGE added within the.asp or.aspx code » »RUNAT attributes (where code is executed) optionally added   Usually placed after the tags   Syntax: » » n n script… » »   Similar to embedded client code

Keep it simple! n n Multiple languages ate not even recommended for different pages in the same application…   makes the ASP.net engine load multiple scripting engines   has to then perform more work to determine which piece of script should be sent to which scripting engine!   reduces the responsiveness and scalability of the application

Some Potential Problems of Scripting in the RAD Environment… n Correct scripting language always needs to be defined at the start of the page  dynamic “new” pages provide a range of options n Inserted controls can:  be inserted in the wrong place…  themselves become muddled n Inserted controls may already contain HTML code or (if database) SQL code

Potential Problems of Scripting in the RAD Environment… (continued) n Embedded server script code may depend on a link to a database  link needs to be functioning correctly…  database field types must correspond with script equivalents n If the database tables/fields change significantly, the script must accommodate the field changes…  roll out changes carefully  may be easier to recreate control or whole page…

Use of Comments in aspx files n n Apostrophe for VBScript   ‘ This is a VBScript comment n n Two slashes for JScript   //This is a JScript comment Three slashes for C#   ///   /// The “myClass” class represents an arbitrary class   /// n n An excellent C# resource:   ents.html ents.html

“Components” and “Objects” n Very similar and easily confused…  object: part of the library of files available to the whole application  component: a number of objects »a mini-application in its own right »any instance of a component must be explicitly created before it can be used n Microsoft provide a library of COM components  IIS ASP environment was mostly COM components!

Using COM in aspx files n n BIG disadvantage of COM (later COM+) components…   VB source code so slow & easy to hack   couldn’t be directly used with.net (even VB.net used a slightly different syntax!) n n BUT… popular with developers…   provided consistent, reusable functionality   easy to maintain and share   could be modified or enhanced without affecting the rest of the application n n Microsoft therefore reluctant to give up a good thing and encouraged using COM+ with.net  

Objects n A series of chunks of server script code that will together provide web functionality  available in a number of languages »asp, asp.net »php, cold fusion  Using RAD tools, added to a dynamic HTML page “at the click of a mouse button” n Several objects usually used together to create a useful web application e.g.  data capture form and sending data to database  presentation of data from a database

Evolution of “VBScript Request” object  “Request” was the only way asp scripts could retrieve the input data entered by the user in the input fields in the page  used to access information passed from the browser when requesting a Web page  handles HTML form fields, client certificate information, and cookies

ASP.net and directing user input  In ASP.NET “HttpRequest” class fulfils same function as obsolete asp request  However..  event handling controls  web controls  Provide great flexibility in the manipulation of user input

Using Server Scripting to Create the Shopping System n Product Information stored on database n Script connects to database n Products can all be displayed on a page n Very useful for users to “click to buy”?  how can clicking behaviour be recorded?  this is where the shopping cart comes in very very handy…

“Shopping Cart” control n A control that sets up the fields that will be used to store the shopping data  could be set up as a code behind file  may be better off as an assembly »needs to be accessed by several.aspx pages »needs to be as fast as possible…  assemblies added to the App_Data folder »usually contain a.dll suffix »need to be formally included with »need to be formally included with

A pre-compiled cart control n Not only has someone written the C# code for a shopping cart for you…  it has already been compiled as well!  found on RH’s website as webxel.dll n Contains quite a lot of dataset fields with specific names  need to be mapped to product pages…  and the cart display page

Parameter Passing between Pages n One of the more effective tricks of server scripting pages with multiple records (!) n How can a click on a hyperlink send a parameter to the cart with a correct value? n Another page uses “get” logic based on a hyperlink with “?”  variable name defined in “get” part  hyperlink picks up the primary key value  allocates this value to the variable used to get the data from the database e.g. ProdID

“Click to buy” Scripting n Product page itself needs to be capable of displaying multiple records  “Repeater” control achieves this most effectively  associated ProductID value for a row relates to the record displayed n The “add” function is built into a page called AddfromDatabase.aspx This page has no HTML but triggers an SQL query to:  pick up this variable value  send the value to the server as ProductID  collect the product description and price fields  save all three values to the dataset

Passing the Product ID Parameter Product Page Add from DB scripts Product ID value sent as e.g. “ProdID” fields extracted from remote database Shopping Cart Remote DB

“Add to Cart” control n This contains the logic to make “click to cart” actually happen  other values such as quantity can then be added to the dataset  dataset record will be equivalent to an “orderline”  values for other products can then be stored in the same dataset but with different orderline values n In any case, the result should be a display of the shopping cart contents

Displaying the Cart Contents n Another carefully designed web page that displays the cart contents and does some simple calculations  you can download this as cart.aspx  it is not too different from the product page  uses a repeater and an HTML table to display products data  differences: »the data is displayed from the cart not the products table »line total and grand total fields used to display each item total, and sum total of all line totals