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.

Slides:



Advertisements
Similar presentations
JQuery MessageBoard. Lets use jQuery and AJAX in combination with a database to update and retrieve information without refreshing the page. Here we will.
Advertisements

Introduction to PHP MIS 3501, Fall 2014 Jeremy Shafer
MIS 3200 – Unit 4 Complex Conditional Statements – else if – switch.
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.
Form Handling, Validation and Functions. Form Handling Forms are a graphical user interfaces (GUIs) that enables the interaction between users and servers.
Microsoft Visual Basic 2005 CHAPTER 8 Using Procedures and Exception Handling.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
PHP : Hypertext Preprocessor
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.
JavaScript & jQuery the missing manual Chapter 11
CSCI 6962: Server-side Design and Programming Introduction to AJAX.
Programming with Microsoft Visual Basic 2012 Chapter 13: Working with Access Databases and LINQ.
XHTML Introductory1 Forms Chapter 7. XHTML Introductory2 Objectives In this chapter, you will: Study elements Learn about input fields Use the element.
Intrinsic Functions Pre-coded Functions Used to improve developer productivity Broad Range of Activities Math calculations Time/Date functions String.
JavaScript, Fourth Edition
PMS /134/182 HEX 0886B6 PMS /39/80 HEX 5E2750 PMS /168/180 HEX 00A8B4 PMS /190/40 HEX 66CC33 By Adrian Gardener Date 9 July 2012.
9 Chapter Nine Compiled Web Server Programs. 9 Chapter Objectives Learn about Common Gateway Interface (CGI) Create CGI programs that generate dynamic.
06/10/ Working with Data. 206/10/2015 Learning Objectives Explain the circumstances when the following might be useful: Disabling buttons and.
 2008 Pearson Education, Inc. All rights reserved Introduction to XHTML.
UNIT 9.2 Learning Objectives A Real world Application of Databases – The Money Ball Example The Money Ball Example Data Warehouses – The Role of Data Warehouses.
UNIT 9.2: Learning Objectives Agile Development – Bruce Feiler on Agile Programming Database access from code – Database Cycle Review – SQL Command Types.
C# Tutorial -1 ASP.NET Web Application with Visual Studio 2005.
MIS 3200 – Unit 4.2 ListItem controls – CheckBoxList – ListBox.
CIS 451: ASP.NET Objects Dr. Ralph D. Westfall January, 2009.
Tutorial 8 Programming with ActionScript 3.0. XP Objectives Review the basics of ActionScript programming Compare ActionScript 2.0 and ActionScript 3.0.
Unit 8.3 Learning Objectives Insert users into the ASP.NET Membership system from code Capture data being sent to the database Capture Exceptions that.
CIS 451: USING ASP.NET TO CREATE XML Dr. Ralph D. Westfall February, 2009.
Intro to More Controls in C#. C# Demonstration We already touched on labels and buttons Ad-hoc demo of controls – Textboxes Multiline – Checkbox – Radiobutton.
1 Κατανεμημένες Διαδικτυακές Εφαρμογές Πολυμέσων Γιάννης Πετράκης.
Variables and ConstantstMyn1 Variables and Constants PHP stands for: ”PHP: Hypertext Preprocessor”, and it is a server-side programming language. Special.
XHTML & Forms. PHP and the WWW PHP and HTML forms – Forms are the main way users can interact with your PHP scrip Typical usage of the form tag in HTML.
MIS 3200 – Unit 5.3 Manipulating ListItem controls – Moving ListItems between ListItem controls – Removing ListItems from ListItem controls.
Java server pages. A JSP file basically contains HTML, but with embedded JSP tags with snippets of Java code inside them. A JSP file basically contains.
Introduction to JavaScript CS101 Introduction to Computing.
XP Tutorial 8 Adding Interactivity with ActionScript.
CIS Intro to JAVA Lecture Notes Set July-05 GUI Programming – Home and reload buttons for the webbrowser, Applets.
Select (drop-down list) Inputs. Insert/Form/List Menu.
1 Project 3 The Kumquat Society Conference. 2 Conference Registration In this project you will write a program to handle a conference registration. The.
Exceptions, handling exceptions & message boxes Year 11 Information Technology.
1 Chapter 3 – Examples The examples from chapter 3, combining the data types, variables, expressions, assignments, functions and methods with Windows controls.
® IBM Software Group © 2006 IBM Corporation JSF Rich Text Area Component This Learning Module describes the use of the JSF Rich Text Area component – for.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
CIS Intro to JAVA Lecture Notes Set July-05 GUI Programming –TextField Action Listeners, JEditorPane action listeners, HTML in a JEditorPane,
MIS 3200 – Unit 3.2 Page_Load method AutoPostBack property of controls IsPostBack method of the Page object Understanding web page life cycle.
MIS 3200 – Unit 5.1 Iteration (looping) – while loops – for loops Working with List Items.
PROGRAMMING IN PYTHON LETS LEARN SOME CODE TOGETHER!
31/01/ Selection If selection construct.
Basic ActionScript and PHP Cis 126. Getting Started set up a basic folder structure so we can keep our files organized. Mirror this structure on your.
1 Project 2: Using Variables and Expressions. 222 Project 2 Overview For this project you will work with three programs Circle Paint Ideal_Weight What.
1 Project 3 String Methods. Project 3: String Methods Write a program to do the following string manipulations: Prompt the user to enter a phrase and.
Calculator Program Explained by Arafa Hamed. First Designing The Interface Ask yourself how many places are there that will be used to input numbers?
PHP Form Processing * referenced from
11 Project 2 Temperature Conversion. 22 Project 2: Temperature Conversion Write an ASP.NET Web Forms app to convert temperatures from Fahrenheit to Celsius.
Files and Streams. Objectives Learn about the classes that support file input/output Understand the concept of abstraction and how it related to the file.
Exception Handling. VB.NET has an inbuilt class that deals with errors. The Class is called Exception. When an exception error is found, an Exception.
World Wide Web has been created to share the text document across the world. In static web pages the requesting user has no ability to interact with the.
111 State Management Beginning ASP.NET in C# and VB Chapter 4 Pages
Unit 9.1 Learning Objectives Data Access in Code
Using Access and the Web
Unit 9.2 Database access from code Database Cycle Review
Exception Handling.
MIS 3200 – Unit 4 Complex Conditional Statements else if switch.
Forms, cont’d.
MIS 3200 – Unit 5.2 ListItem controls and accumulation
Exception Handling.
MIS 3200 – Unit 5.1 Iteration (looping) Working with List Items
PHP-II.
MIS 3200 – Unit 6.1 Moving between pages by redirecting
MIS 3200 – Unit 2.2 Outline What’s the problem with bad data?
Presentation transcript:

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

Query Strings – What are they? Query strings: – are found at the end of the URL. fox example: – can be used to pass data from one page to another (Any other ways?)

Query String: Characteristics Query strings: – are started with a question mark (?) – can contain any number of “keys” (i.e. name – value pairs) – Different Keys which are separated with an ampersand (&) – Words within the values are separated by a plus sign ( + ) Unit6L22.aspx?userName=Shannon+Prescott&subTotal=270.35;

How are query strings created? Query strings are manually built by the developer and used with Response.Redirect When this code executes, the user will be sent to the target and will pass along two keys via the query string: – userName which is assigned a value of “Shannon Prescott” – subTotal which is assigned a value of “270.35” Begin the page redirection Query strings can be built like any other string you have worked with. Using concatenation we can construct a query string that will use values from TextBoxes on a page, for example: When this code executes, the user will be sent to Unit6L22.aspx and will pass along two values via the query string: – So effectively, the key, UserName= txtName.Text – and the key, subTotal = lblSubTotal.Text Response.Redirect(“Unit6L22.aspx?UserName=“ + txtName.Text + “&subTotal=“ + lblSubTotal.Text); Response.Redirect(“Unit6L22.aspx”);

How are query strings read? Query strings are typically read on the target pages Request.Querystring allows retreieval of the key and its value, for example: When this code executes, the value assigned to the key will be read from the query string, converted to string so that it can be placed in the Text property of a label on our page. When reading the query string keys, you must use brackets [] around the name of the key: Another example, but this time we have to convert our query string since we want to perform math on it: When this code executes, the value assigned to SubTotal key will be read from the query string, converted to a decimal, and assigned to decValue. Based on the previous slide, the value is lblName.Text = Request.Querystring[“UserName”].ToString(); lblWecomeString.Text = “Hello” + Request.Querystring[“UserName”].ToString(); lblWecomeString.Text += “Your sub-total is $“ + Request.Querystring[“SubTotal”].ToString(); lblWecomeString.Text = “Hello” + Request.Querystring[“UserName”].ToString(); lblWecomeString.Text += “Your sub-total is $“ + Request.Querystring[“SubTotal”].ToString(); decimal intValue = 0m; decValue = Convert.ToDecimal(Request.QueryString[“SubTotal”]);

Error messages! What happens if we try to read a key that does not exist? When this code executes, and if key3 does not exist we will get an error message: Why does this happen? int intValue = 0m; intValue = Convert.ToDecimal(Request.QueryString[“key3”]);

Prevent errors – clever code One way to address the problem is to see if the key exists by using a conditional test: When this code executes, and if key3 does not exist, intValue is still set to 0

Issues with preventing errors But, wait! What if key3 exists, but has a value set to cat? The conditional test will pass, but we will run into an error if we try to convert “cat” to an integer? ERROR! >>> “Input string was not in a correct format”

Controlling error messages with Try – Catch Using a Try – Catch statement allows us to “try” to execute some code and if there is an error (an Exception) it will “catch” the error and let you decide what to do with it.

Controlling error messages with Try – Catch #2 So, in the previous key3 example we could modify the code to look like this:

Hands On – Unit 6 L22 Creating and reading query strings 1.Create 2 new files in your Unit 6 folder lastnameU6L22_1.aspx and lastnameU6L22_2.aspx 2.Update the heading to be Unit 6 L22_1 – Creating Query Strings (in the 1 st file) and Unit 6 L22_2 – Reading Query Strings (in the 2 nd file) 3.In U6L22_1.aspx, add 3 text boxes and a button a.Set the button text to Pass the values to the next page

L2.2 #2 4.In the button click method of the Pass the values to the next page create a query string which passes the values of the 3 text boxes to the U6L22_2.aspx page 5.In U6L22_2.aspx, a.add a label (which will display the contents of the query string) b.add a button with the Text set to Change the values and in the button click method, redirect the user back to the 1 st page c.When the 2 nd page loads, you should display the contents of the all keys passed in the query string in the label. Additionally, if a key can be converted into a decimal (e.g. somebody type in 2.0 into one of the text boxes), display a message that the key is a decimal; otherwise, display a message the key is NOT a decimal d.For an example of what the page should be, see the link below:

L2.2 #3 6.Test the L2.2 functionality by typing in 2.0 in the 1 st textbox, dog in the 2 nd textbox and 4 into the 3 rd textbox it should look similar to this example: Add appropriate comments to explain what the the methods are doing 8.Create a link to your U6L22_1.aspx page from your MIS3200 page and copy everything to ASPNET and submit your MIS Portfolio URL to the drop box.

Think About It! Why is try – catch critical to usability of applications? When should query strings be used instead of session variables? When should you NOT use query strings? From this point forward your assignments should NEVER crash – ALWAYS use try/catch to protect any code that might crash AND always provide meaningful messages when an Exception is caught.