Mark Dixon Page 1 16 – Passing Data between pages: Forms, Sessions, & Query Strings.

Slides:



Advertisements
Similar presentations
MFA for Business Banking – Security Code Multifactor Authentication: Quick Tip Sheets Note to Financial Institutions: We are providing these QT sheets.
Advertisements

CTER Orientation Tutorial The Use of the WebBoard.
Web Shift Booking System
30/04/ Selection Nested If structures & Complex Multiple Conditions.
Copyright © The OWASP Foundation Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation.
Introduction to Online Data Collection (OLDC) Community Based Abstinence Education September, 2009.
Welcome to Florida International University Online J.O.B.S. Link Applicant Tutorial.
Mark Dixon Page 1 22 – Object Oriented Programming in ASP.
Mark Dixon, SoCCE SOFT 131Page 1 20 – Web applications: HTML and Client-side code.
Mark Dixon Page 1 02 – Dynamic HTML (client-side scripting)
Mark Dixon Page 1 15 – Web applications: Server-side code (ASP)
Mark Dixon, SoCCE SOFT 131Page 1 16 – Web applications: HTML and Client-side code.
Mark Dixon Page 1 21 – Object Oriented Programming in ASP.
Mark Dixon, SoCCE SOFT 131Page 1 16 – Passing Data between pages: Sessions, Query Strings, & Self Posting.
Mark Dixon Page 1 02 – Queries: Query by Example.
Mark Dixon Page 1 20 – Web applications: Writing data to Databases using ASP.
Mark Dixon Page 1 15 – Web applications: Server-side code (ASP)
Mark Dixon, SoCCE SOFT 131Page 1 19 – Web applications: Server-side code (ASP)
Mark Dixon, SoCCE SOFT 131Page 1 08 – Web applications: HTML and ActiveX controls.
Mark Dixon, SoCCE SOFT 131Page 1 20 – Web applications: Writing data to Databases using ASP.
Christopher M. Pascucci Basic Structural Concepts of.NET Browser – Server Interaction.
McGraw-Hill/Irwin © 2004 by The McGraw-Hill Companies, Inc. All rights reserved. Beginning Active Server Pages Barry Sosinsky Valda Hilley Programming.
Welcome to the University of Florida Online Employment System Applicant Tutorial.
Welcome to the Southeastern Louisiana University’s Online Employment Site Applicant Tutorial!
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.
Mark Dixon Page 1 19 – Passing Data between pages: Forms, Sessions, & Query Strings.
Mark Dixon Page 1 23 – Web applications: Writing data to Databases using PhP.
Session 10: Managing State. Overview State Management Types of State Management Server-Side State Management Client-Side State Management The Global.asax.
Mark Dixon Page 1 24 – Object Oriented Programming in ASP.
Mark Dixon 1 07 – Variables. Mark Dixon 2 Questions: Conditional Execution What is the result of (txtFah.value is 50): (txtFah.value >= 40) What will.
Mark Dixon Page 1 3 – Web applications: Server-side code (JSP)
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.
Mark Dixon Page 1 09 – Arrays. Mark Dixon Page 2 Questions: Loops What is the value of t, after this code executes? t = 0 For x = 4 To 6 t = t + x Next.
CTER Orientation Tutorial The Use of the WebBoard.
Online Substantive Process TRUST MANAGERS Self Teach Tutorial April 2008 Version 1.0.
Mark Dixon 1 18 – Web applications: Server-side code (ASP.Net)
Mark Dixon Page 1 18 – Web applications: Server-side code (ASP)
Mark Dixon Page 1 18 – Web applications: Server-side code (PhP)
Lecture 8 – Cookies & Sessions SFDV3011 – Advanced Web Development 1.
Mark Dixon 1 11 – Array Variables. Mark Dixon 2 Questions: Loops What is the value of t, after this code executes? t = 0 For x = 4 To 6 t = t + x Next.
Mark Dixon Page 1 10 – Array Variables. Mark Dixon Page 2 C1 – In-class test Results mixed: –quite a few fails 34% (13/38) –some very good (91% max) ask.
Mark Dixon 1 03 – Passing Data between pages: Forms, Sessions, & Query Strings.
10 August 2005Benchmark/Mentor Student Guide Page 1 CPS Benchmark/Mentor Student Guide Internet Edition.
Mark Dixon, SoCCE SOFT 131Page 1 05 – Variables. Mark Dixon, SoCCE SOFT 131Page 2 Admin: Test (next week) In class test –teaching week 6 –university week.
STATE MANAGEMENT.  Web Applications are based on stateless HTTP protocol which does not retain any information about user requests  The concept of state.
Mark Dixon Page 1 21 – Web applications: Writing data to Databases using ASP.
Mark Dixon, SoCCE SOFT 131Page 1 24 – Datatypes and Object Association.
Mark Dixon 1 19 – Passing Data between pages: Forms, Sessions, & Query Strings.
ASP. What is ASP? ASP stands for Active Server Pages ASP is a Microsoft Technology ASP is a program that runs inside IIS IIS stands for Internet Information.
Mark Dixon 1 9 – Case Study. Mark Dixon 2 Session Aims and Objectives Aims –To give an overview of the development of a web-page from initial idea to.
Mark Dixon Page 1 08 – Variables. Mark Dixon Page 2 Questions: Conditional Execution What is the result of (txtFah.value is 50): (txtFah.value >= 40)
Mark Dixon Page 1 08 – Variables. Mark Dixon Page 2 Questions: Conditional Execution What is the result of (txtFah.value is 50): (txtFah.value >= 40)
Mark Dixon Page 1 15 – Web applications: Server-side code (ASP)
Mark Dixon 1 22 – Object Oriented Programming. Mark Dixon 2 Questions: Databases How many primary keys? How many foreign keys? 3 2.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
1 State and Session Management HTTP is a stateless protocol – it has no memory of prior connections and cannot distinguish one request from another. The.
31/01/ Selection If selection construct.
MIT AITI 2004 JSP – Lecture 4 Sessions and Cookies.
ITM © Port,Kazman 1 ITM 352 Cookies. ITM © Port,Kazman 2 Problem… r How do you identify a particular user when they visit your site (or any.
PHP Form Processing * referenced from
9 – Web applications: Server-side code (ASP)
21 – Web applications: Server-side code (ASP)
18 – Web applications: Server-side code (PhP)
18 – Web applications: Server-side code (ASP)
17 – Modular Design in ASP.
ITM 352 Cookies.
12 – Passing Data between pages: Forms, Sessions, & Query Strings
Introduction to TouchDevelop
Presentation transcript:

Mark Dixon Page 1 16 – Passing Data between pages: Forms, Sessions, & Query Strings

Mark Dixon Page 2 Session Aims & Objectives Aims –To introduce the fundamental ideas involved in passing data between pages Objectives, by end of this week’s sessions, you should be able to: –pass data between pages, using: Self Posting Query Strings Session Variables

Mark Dixon Page 3 Example: Logon v2 (design) Restrict access to home page

Mark Dixon Page 4 Example: Logon v2 (code) Sub Page_Load() Dim un As String Dim pw As String If Request.Form("btnLogon") > "" Then un = txtUserName.Value pw = txtPassWord.Value If un = "mark" And pw = "soft131" Then Response.Redirect("home.htm") Else msg.innerText = "Login details incorrect." End If End Sub Please logon: Logon.aspx My Home page Welcome to my home page. Home.htm

Mark Dixon Page 5 Example: Logon (Fixed Problem) View Source – shows client-side script: No server-side code

Mark Dixon Page 6 Example: Logon (Problem 2) User can type home page url (address) directly (bypassing logon page)

Mark Dixon Page 7 Solution Need way for: –password page to tell home page –that user logged in OK

Mark Dixon Page 8 Technique: Dead-Drop Variables 2 Spies wish to pass message between each other without actually meeting Arrange a dead-drop location –one spy leaves message at location –other spy visits location later to pick up message Variables used as dead-drop containers

Mark Dixon Page 9 Example: Logon v3 (code) Dim LogonOK As Boolean Sub Page_Load() Dim un As String Dim pw As String LogonOK = False If Request.Form("btnLogon") > "" Then un = txtUserName.Value pw = txtPassWord.Value If un = "mark" And pw = "soft131" Then LogonOK = True Response.Redirect("home3.htm") Else msg.innerText = "Login details incorrect." End If End Sub Please logon: Logon3.aspx Dim LogonOK As Boolean Sub Page_Load() If LogonOK = False Then Response.Redirect("Logon3.aspx") End If End Sub My Home page Welcome to my home page. Home3.aspx Error: always redirect to logon LogonOK True

Mark Dixon Page 10 Example: Logon v3 (Error) Variables – don't persist between pages

Mark Dixon Page 11 Passing Data (temporary) Session object –used to pass information between pages: –exists for current session –persist between pages –clears if user closes browser –clears after 20 mins of inactivity –no need for declaration Session("Thing") = 91 Put 91 into Thing

Mark Dixon Page 12 Maintaining State: Session Object Sub Page_Load() If Request.Form("btnSend") > "" Then Session("MSG") = "Meet in BGB202" ElseIf Request.Form("btnClear") > "" Then Session.Abandon() End If End Sub Display Send.aspx Session variable –all strings –no declaration Abandon method –deletes all session variables

Mark Dixon Page 13 Maintaining State: Session Object Sub Page_Load() parMsg.InnerText = Session("MSG") End Sub Display.aspx read session variable, and display in parMsg

Mark Dixon Page 14 Example: Message Using Session variable: Sub Page_Load() If Request.Form("btnSend") > "" Then Session("MSG") = "Meet in BGB202" ElseIf Request.Form("btnClear") > "" Then Session.Abandon() End If End Sub Display Send.aspx Sub Page_Load() parMsg.InnerText = Session("MSG") End Sub Display.aspx MSG Meet in BGB202

Mark Dixon Page 15 Questions: Session Variables Write a line of VB code to put the number 74 into a session variable called id. Write VB code that displays 'Hello' in parMsg if the session variable called id is equal to 74 Session("id") = 74 If Session("id") = 74 Then parMsg.InnerText = "Hello" End If

Mark Dixon Page 16 Example: Apples (analysis) SPECIFICATION User Requirements –help children learn numbers Software Requirements –Functional: –display random number of apples (between 1 & 10) –ask child how many apples are there –child enters answer –computer responds appropriately –Non-functional should be easy to use, and interesting

Mark Dixon Page 17 Example: Apples (code) What will this do? Dim n As Long Sub Page_Load() Dim html As String Dim a As Long If Request.Form("btnStart") > "" Then n = 1 + Int(Rnd() * 9) html = "How many apples are there? " For a = 1 To n html = html & " " Next quest.InnerHtml = html ElseIf Request.Form("btnCheck") > "" Then If CInt(txtAns.Value) = CInt(n) Then msg.InnerHtml = "Correct, well done!" Else msg.InnerHtml = "Sorry, please try again." End If End Sub Apples.aspx

Mark Dixon Page 18 Passing Data (temporary) Query Strings –Useful for passing information between pages via links

Mark Dixon Page 19 Maintaining State: Query Strings Data added to end of URL (address): ASP code can use this data: –Request.QueryString("Surname") would return the value "Bob" Form method=get –data automatically added to query string Query String

Mark Dixon Page 20 Example: Date-Time What background colour do you want for you date information? Yellow Light Blue Menu.aspx > The date is. The time is. DateTime.aspx

Mark Dixon Page 21 Reference: Server Object Model Request object: calling web page –Form: used to get form data from page –QueryString: used to get data from address (?) Response object: web page sent back –Write: used to put text into web page –Redirect: used to navigate to other page –Clear: erases all HTML in web page Session object: store data between pages –Abandon: clears session data

Mark Dixon Page 22 Passing Data (persistent) Cookies (not covered in this module) –stored on users’ (client) hard drive –persists between sessions Database/file (covered in later lectures) –stored on server hard drive –persists between sessions

Mark Dixon Page 23 Tutorial Exercise: Message LEARNING OBJECTIVE: pass data between pages using session variables, and (form) self-posting Task 1: Get the message example working (from the lecture) Task 2: Change the send.aspx page so that when you click the buttons it gives some feedback as to what has happened. hint: add a paragraph

Mark Dixon Page 24 Tutorial Exercise: Apples LEARNING OBJECTIVE: pass data between pages using session variables, and (form) self-posting Task 1: Type in the code for the Apples example (from the lecture) Task 2: Modify this to use a session variable to 'remember' the random number, so that it works. Task 3: Change it so that it disables the buttons appropriately Task 4: Change it so that it clears the text box and feedback as a new question begins

Mark Dixon Page 25 Tutorial Exercise: Logon LEARNING OBJECTIVE: pass data between pages using session variables, and (form) self-posting Task 1: Type in the code for the Logon v3 example (from the lecture) NOTE: this will not work properly (variables do not persist between pages) Task 2: Modify this to use a session variable to 'remember' whether the logon was successful. Note: It should not be possible to view the source code Note: It should not be possible to bypass the logon

Mark Dixon Page 26 Tutorial Exercise: Date LEARNING OBJECTIVE: pass data between pages using query strings Task 1: Get the Date-Time example (from the lecture) working Task 2: Modify your page to provide another choice of background colour.