Tips, Trick and Techniques for ASP Developers Atlanta ASP User Group Don Draper Draper Consulting, Inc.

Slides:



Advertisements
Similar presentations
LIS651 lecture 3 taming PHP Thomas Krichel
Advertisements

WEB DESIGN TABLES, PAGE LAYOUT AND FORMS. Page Layout Page Layout is an important part of web design Why do you think your page layout is important?
Cookies, Sessions. Server Side Includes You can insert the content of one file into another file before the server executes it, with the require() function.
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.
1 Chapter 12 Working With Access 2000 on the Internet.
CS320 Web and Internet Programming Generating HTTP Responses
HTTP Hypertext Transfer Protocol. HTTP messages HTTP is the language that web clients and web servers use to talk to each other –HTTP is largely “under.
How the web works: HTTP and CGI explained
HTTP Overview Vijayan Sugumaran School of Business Administration Oakland University.
Christopher M. Pascucci Basic Structural Concepts of.NET Browser – Server Interaction.
CST JavaScript Validating Form Data with JavaScript.
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.
1 Forms for the Web Tom Muck
1 Web Developer & Design Foundations with XHTML Chapter 6 Key Concepts.
PHP Tutorials 02 Olarik Surinta Management Information System Faculty of Informatics.
Advance Database Management Systems Lab no. 5 PHP Web Pages.
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.
1 CS 3870/CS 5870 Static and Dynamic Web Pages ASP.NET and IIS.
FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA1 Part 4 Web technologies: HTTP, CGI, PHP,Java applets)
INTERNET APPLICATION DEVELOPMENT For More visit:
Copyright 2007, Information Builders. Slide 1 Maintain & JavaScript: Two Great Tools that Work Great Together Mark Derwin and Mark Rawls Information Builders.
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting Cookies & Sessions.
1 HTML and CGI Scripting CSC8304 – Computing Environments for Bioinformatics - Lecture 10.
Krerk Piromsopa. Web Caching Krerk Piromsopa. Department of Computer Engineering. Chulalongkorn University.
CHAPTER 12 COOKIES AND SESSIONS. INTRO HTTP is a stateless technology Each page rendered by a browser is unrelated to other pages – even if they are from.
Chapter 5 Java Script And Forms JavaScript, Third Edition.
Chapter 6: Forms JavaScript - Introductory. Previewing the Product Registration Form.
Overview of Previous Lesson(s) Over View  ASP.NET Pages  Modular in nature and divided into the core sections  Page directives  Code Section  Page.
CSC 2720 Building Web Applications Getting and Setting HTTP Headers (With PHP Examples)
JavaScript, Fourth Edition
WEEK 3 AND 4 USING CLIENT-SIDE SCRIPTS TO ENHANCE WEB APPLICATIONS.
Web Programming: Client/Server Applications Server sends the web pages to the client. –built into Visual Studio for development purposes Client displays.
1 Accelerated Web Development Course JavaScript and Client side programming Day 2 Rich Roth On The Net
Chapter 8 Cookies And Security JavaScript, Third Edition.
Using Client-Side Scripts to Enhance Web Applications 1.
 2008 Pearson Education, Inc. All rights reserved Introduction to XHTML.
Website Development with PHP and MySQL Saving Data.
 Whether using paper forms or forms on the web, forms are used for gathering information. User enter information into designated areas, or fields. Forms.
LOGO FORMs in HTML CHAPTER 5 Eastern Mediterranean University School of Computing and Technology Department of Information Technology ITEC229 Client-Side.
Christopher M. Pascucci Basic Structural Concepts of.NET Managing State & Scope.
7 Chapter Seven Client-side Scripts. 7 Chapter Objectives Create HTML forms Learn about client-side scripting languages Create a client-side script using.
1-1 HTTP request message GET /somedir/page.html HTTP/1.1 Host: User-agent: Mozilla/4.0 Connection: close Accept-language:fr request.
Introduction to JavaScript CS101 Introduction to Computing.
JavaScript Scripting language What is Scripting ? A scripting language, script language, or extension language is a programming language.
HTML Forms. Slide 2 Forms (Introduction) The purpose of input forms Organizing forms with a and Using different element types to get user input A brief.
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.
Operating Systems Lesson 12. HTTP vs HTML HTML: hypertext markup language ◦ Definitions of tags that are added to Web documents to control their appearance.
CITA 310 Section 2 HTTP (Selected Topics from Textbook Chapter 6)
ECMM6018 Enterprise Networking for Electronic Commerce Tutorial 7
Web Services. 2 Internet Collection of physically interconnected computers. Messages decomposed into packets. Packets transmitted from source to destination.
 2001 Prentice Hall, Inc. All rights reserved. Chapter 7 - Introduction to Common Gateway Interface (CGI) Outline 7.1Introduction 7.2A Simple HTTP Transaction.
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.
ASP-2-1 SERVER AND CLIENT SIDE SCRITPING Colorado Technical University IT420 Tim Peterson.
(Some from Chapter 11.9 – “Web” 4 th edition and
PHP and Sessions. Session – a general definition The GENERAL definition of a session in the “COMPUTER WORLD” is: The interactions (requests and responses)
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.
1 PHP HTTP After this lecture, you should be able to know: How to create and process web forms with HTML and PHP. How to create and process web forms with.
Internet & World Wide Web How to Program, 5/e Copyright © Pearson, Inc All Rights Reserved.
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.
Session 11: Cookies, Sessions ans Security iNET Academy Open Source Web Development.
27.1 Chapter 27 WWW and HTTP Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
INTERNET APPLICATIONS CPIT405 Forms, Internal links, meta tags, search engine friendly websites.
PHP: Further Skills 02 By Trevor Adams. Topics covered Persistence What is it? Why do we need it? Basic Persistence Hidden form fields Query strings Cookies.
© Janice Regan, CMPT 128, Jan 2007 CMPT 371 Data Communications and Networking HTTP 0.
Y.-H. Chen International College Ming-Chuan University Fall, 2004
ASP Explained By: Sarbjit Kaur.
19.10 Using Cookies A cookie is a piece of information that’s stored by a server in a text file on a client’s computer to maintain information about.
IS333D: MULTI-TIER APPLICATION DEVELOPMENT
The Request & Response object
Presentation transcript:

Tips, Trick and Techniques for ASP Developers Atlanta ASP User Group Don Draper Draper Consulting, Inc.

February 10, 2000 Draper Consulting, Inc. Topics Transact-SQL Techniques Handling Expired Session Techniques Background Images in Tables JavaScript Tips The Response Object Understanding HTTP Headers

February 10, 2000 Draper Consulting, Inc. Transact-SQL Techniques

February 10, 2000 Draper Consulting, Inc. Transact-SQL, Technique #1 Ad-Hoc WHERE Clause Problem: User can enter any selection criteria in multiple fields for ad-hoc query, but data source is a stored procedure. Solution: WHERE (col1 is null) AND (col2 is null) AND (col3 is null )

February 10, 2000 Draper Consulting, Inc. Transact-SQL, Technique #1 Ad-Hoc WHERE Clause In ASP Code… –Make sure empty parameters are passed as nulls if parm = empty then parm = null –Can use Parameter Object Set param1 = cmd.CreateParameter ("city", adVarChar,adParamInput,15,city) Set param2 = cmd.CreateParameter ("company", adVarChar, adParamInput, 40, company) cmd.Parameters.Append param1

February 10, 2000 Draper Consulting, Inc. Transact-SQL, Technique #1 Ad-Hoc WHERE Clause In ASP Code… –Can use Array function to pass params city = request("city") if city = empty then city = Null ‘ pass null to sp if not needed Set rs = cmd.Execute (recs, Array( company, city ) )

February 10, 2000 Draper Consulting, Inc. Transact-SQL, Technique #1 Ad-Hoc WHERE Clause In Stored Procedure… – default arguments to varchar(40) = null, … – use “Is null”..NOT “= null” Good: WHERE (company is null) Bad: WHERE (company = null)

February 10, 2000 Draper Consulting, Inc. Transact-SQL, Technique #2 Ad-Hoc ORDER BY Clause Problem: User can click on any header in table and the result set is reordered for that column. However, the data source is a stored procedure. How can I alter ORDER BY clause? Solution #1: Use Exec() –lose precompiled advantage of stored proce Solution #2: Use ANSI CASE (better) –Retain precompiled advantage of stored proc

February 10, 2000 Draper Consulting, Inc. Transact-SQL, Technique #2 Ad-Hoc ORDER BY Clause Sample Code for Stored Procedure ORDER BY  passed in a argument to procedure WHEN 'id' THEN CAST (CustomerID as varchar(20)) WHEN 'companyname' THEN companyname WHEN 'city' THEN city ELSE CAST (CustomerID as varchar(20)) END

February 10, 2000 Draper Consulting, Inc. Handling Expired Sessions

February 10, 2000 Draper Consulting, Inc. Handling Expired Sessions We use sessions to … –Maintain state information –Maintain user specific data across pages –Provide additional security…and more Sessions end by –Session.Abandon –Session expires due to period of inactivity

February 10, 2000 Draper Consulting, Inc. Handling Expired Sessions When session expires –Need user to start over login again start new session & re-establish session data Techniques to check for current session –Check for session value at top of page –Let session events handle it for you!

February 10, 2000 Draper Consulting, Inc. Handling Expired Sessions Typical Technique: –Check for session variable at the top of each page If session(“userid”) = “” then redirect(“login.asp”) End if

February 10, 2000 Draper Consulting, Inc. Handling Expired Sessions Suggested Technique: –Let a session event handle it for you –In Global.ASA file Session_OnStart Check referring URL Redirect/Transfer if not coming from your start (login?) page fromURL = Request.ServerVariables("URL") if InStr(lcase(fromURL), "login.asp") = 0 then Response.Redirect("expired_page.asp") end if

February 10, 2000 Draper Consulting, Inc. Handling Expired Sessions Watch out for… –login page is ASP page Session already started before login –Use –Use Session.Abandon to kill session –other pages that start session before login Same as above –use NT Performance Monitor to watch session count when testing

February 10, 2000 Draper Consulting, Inc. Background Images in Tables

February 10, 2000 Draper Consulting, Inc. Background Images in Tables Table background images offer an easy way to place other elements over an image. Cell can be used for positioning.

February 10, 2000 Draper Consulting, Inc. Background Images in Tables Problem: Background images can be defined as an attribute of a TABLE tag. This permits elements such as text, fields and more to be place over an image. However, Netscape renders the image starting in each cell, even if defined at the TABLE level!

February 10, 2000 Draper Consulting, Inc. Background Images in Tables..

February 10, 2000 Draper Consulting, Inc. Background Images in Tables Netscape renders the image inside each cell, even if defined at the TABLE level. As you can see, this is not acceptable!

February 10, 2000 Draper Consulting, Inc. Background Images in Tables Solution: Use two nested tables –Outer table gets one empty cell to hold inner table background attribute defined in Table tag –Inner table background attribute in Table tag but with empty value ( background=“” ) Use cells to position elements over image

February 10, 2000 Draper Consulting, Inc. Client-Side JavaScript

February 10, 2000 Draper Consulting, Inc. Client-Side JavaScript Two common uses… –Place cursor in appropriate form field –Client-side form validation Place cursor in appropriate form field document.formname.fieldname.focus();

February 10, 2000 Draper Consulting, Inc. Client-Side JavaScript Place cursor in UID field if empty…otherwise place in password field <!-- hide from old browsers function set_focus( ) { if (document.forms[0].as_userid.value.length > 0) document.forms[0].as_password.focus(); else document.forms[0].as_userid.focus(); } // -->

February 10, 2000 Draper Consulting, Inc. Client-Side JavaScript Use // to comment out closing HTML comments <!-- function myfunction( ) { } // -->  the js comment (//) prevents errors in some browsers

February 10, 2000 Draper Consulting, Inc. Client-Side JavaScript FormChek.js - Form Validation Library Free, Public Domain Library Over 60K of validation routines by Eric Krock, NS –Basic data validation routines –Reformat data –Prompt user –Interactively check field contents –Credit card validation

February 10, 2000 Draper Consulting, Inc. Understanding HTTP Headers

February 10, 2000 Draper Consulting, Inc. Understanding HTTP Headers? Request Headers (from browser) –GET- hyperlink request –POST- FORM request (default) Response Headers (from server or ASP code) –Content-Type:- defines type of content –Location: - redirect browsers to URL –Set-Cookie:- stores data on browser

February 10, 2000 Draper Consulting, Inc. Pages / ASP FunctionA( ) FunctionB( ) FunctionC(a).. Pages / ASP FunctionA( ) FunctionB( ) FunctionC(a).. Request & Response IIS / ASP (server) Web browser HTTP Request HTTP Response GET URL HTTP/1.0 HTML page or binary content (PDF) prefixed with HTTP Response Headers

February 10, 2000 Draper Consulting, Inc. HTTP Response Headers My Web Page! My Web Page! HTTP/ OK Server: Apache/1.1.1 Content-Type: text/html Content-Length: HTML Page HTTP Headers

February 10, 2000 Draper Consulting, Inc. HTTP Header Format Each header is on its own line with no blank lines between them The last header is followed by a blank line and then the content

February 10, 2000 Draper Consulting, Inc. HTTP Headers My Web Page! My Web Page! HTTP/ OK Server: Apache/1.1.1 Content-Type: text/html Content-Length: text/html HTML Page Headers added by Web Server Headers you can control One blank line separates headers from content

February 10, 2000 Draper Consulting, Inc. Common HTTP Response Headers Location: (redirection) Content-Type: (MIME type of content) Content-Length: (length of content) Set-Cookie: (save data on browser)

February 10, 2000 Draper Consulting, Inc. The Response Object

February 10, 2000 Draper Consulting, Inc. The Response Object Collections –Cookies Properties –Buffer –CacheControl –CharSet –ContentType –Expires –ExpiresAbsolute –IsClientConnected –Status Methods –AddHeader –AppendToLog –BinaryWrite –Clear –End –Flush –PICS –Redirect –Write

February 10, 2000 Draper Consulting, Inc. The Response Object Collections – Properties –Buffer – Methods –AddHeader – –Clear –End –Flush – –Redirect –

February 10, 2000 Draper Consulting, Inc. Tips for Using Flush and End Response.Flush –Flush after page titles but before long database queries to increase perception of speed –Output continue to fill buffer after Flush is used –Response.Buffer must be TRUE Response.End –Stops further output to the browser –Use Clear to remove output prior to End

February 10, 2000 Draper Consulting, Inc. Tips for Using Clear and Redirect Response.Clear –Clear page content since the last Flush or Clear; headers are still sent –Useful to display only error message instead of standard page content Response.Redirect –Sends 302 Object Moved response error –Buffer must be true if content already sent –Don’t need Clear prior to Redirect

February 10, 2000 Draper Consulting, Inc. Redirect(“file2.asp”) Request & Response Redirect Requires 2 Round Trips to Server IIS / ASP (server) Web browser Request: GET /file1.asp HTTP/1.0 Response: 302 Object Moved Location: file2.asp Request: GET /file2.asp HTTP/1.0 File1.asp File2.asp Response: 200 Ok HTTP/ OK Server: Microsoft-IIS/4.0 Date: Wed, 16 Feb :26:53 GMT Content-Length: 218 Content-Type: text/html

February 10, 2000 Draper Consulting, Inc. Server.Transfer(“File2.ASP”) Request & Response Server.Transfer Requires Only 1 Trip to Server (ASP 3.0) IIS / ASP 3.0 (server) Web browser Request: GET /file1.asp HTTP/1.0 File1.asp File2.asp Response: 200 Ok HTTP/ OK Server: Microsoft-IIS/4.0 Date: Wed, 16 Feb :26:53 GMT Content-Length: 218 Content-Type: text/html Server send back different file

February 10, 2000 Draper Consulting, Inc. More Information Ostrosoft Internet Tools – HTTP Protocol and Headers – FormChek.js –Look in search engines –

February 10, 2000 Draper Consulting, Inc. More Information Wrox Books –Professional Active Server Pages 2.0 (3.0) –ASP 2.0 (2.1) Programmers Reference –ADO 2.0 (2.5) Programmers Reference – –

February 10, 2000 Draper Consulting, Inc. Questions?

February 10, 2000 Draper Consulting, Inc. Presentation Survey Results