Post on 16-Oct-2021
transcript
ASP Web Development with Macromedia
Dreamweaver MX 2004
RACHEL ANDREW AND ROB TURNBULL WITH
AlAN FOLEY AND DREW MCLELLAN
APress Media, LLC
ASP Web Development with Macromedia Dreamweaver MX 2004 Copyright© 2004 by Rachel Andrew and Rob Turnbull with Alan Foley and Drew Mclellan Originally published by Apress in 2004
All rights reserved No part of this work may be reproduced or transmitted in any form or by any means, electronic or mechanical, including photocopying, recording, or by any information storage or retrieval system, without the prior written permission of the copyright owner and the publisher.
ISBN 978-1-59059-349-3 ISBN 978-1-4302-0722-1 (eBook) DOI 10.1007/978-1-4302-0722-1
Trademarked names may appear in this book. Rather than use a trademark symbol with every occurrence of a trademarked name, we use the names only in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark.
Technical Reviewer: Matt Machell
Editorial Board: Steve Anglin, Dan Appleman, Gary Cornell, James Cox, Tony Davis, John Franklin, Chris Mills, Steven Rycroft, Dominic Shakeshaft, Julian Skinner, Jim Sumser, Karen Watterson, Gavin Wray, John Zukowski
Assistant Publisher: Grace Wong
Project Manager: Sofia Marchant
Copy Editor: Nancy Depper
Production Manager: Kari Brooks
Production Editor: Noemi Hollander
Proofreader: linda Seifert
Compositor: Diana Van Wmlde, Van Wmlde Design Group
Indexer: Carol Burbo
Cover Designer: Kurt Krames
Manufacturing Manager: Tom Debolski
In the United States: phone 1-800-SPRINGER, email orders@springer-ny. corn, or visit http: //lroWW. springer-ny .corn. Outside the United States: fax +49 6221 345229, email orders@springer. de, or visit http: 1 !"tMW. springer. de.
For information on translations, please contact Apress directly at 2560 Ninth Street, Suite 219, Berkeley, CA 94710. Phone 510-549-5930, fax 510-549-5939, email info@apress. corn, or visit http:/ /"tMW.apress.corn.
The information in this book is distributed on an "as is" hasis, without warranty. Although every precaution bas been taken in the preparation of this work, neither the author(s) nor Apress shall have any liability to any person or entity with respect to any loss or damage caused or alleged to be caused directly or indirectly by the information contained in this work.
Contents at a Glance
About the Authors ............................................................................................. xiii About the Technical Reviewer ...................................................................... xv Acknowledgments ................................................................................................. xvii
Chapter 1 Introducing Dreamweaver MX 2004 ..................................... 1
Chapter 2 Web Standards in Dreamweaver .......................................... 23
Chapter 3 Accessibility and Dreamweaver MX 2004 ...................... 89
Chapter 4 Introducing ASP .................................................................... 115
Chapter 5 Databases Overview ............................................................. 171
Chapter 6 The Application Panel ....................................................... 233
Chapter 7 Code Reuse in Dreamweaver .............................................. 285
Chapter 8 Dreamweaver MX 2004 Extensions ................................... 321
Chapter 9 Debugging and Error Handling ........................................ 347
Chapter 10 Final Case Study .................................................................. 379
Index ...................................................................................................................... 407
iii
Contents
About the Authors ............................................................................................. xiii About the Technical Reviewer ...................................................................... xv Acknowledgments ................................................................................................. xvii
Chapter 1 Introducing Dreamweaver MX 2004 ......................... 1
Static to Dynamic ................................................................................................ 2 Server-Side Technology in Dreamweaver MX ................................................... 2 Why You Need Dreamweaver MX 2004 ............................................................. 3
Moving Around in Dreamweaver MX 2004 ....................................................... 6 TheMDI ............................................................................................................... 6 The Panels ............................................................................................................ 9
Summary .................................................................................................................... 2o
Chapter 2 Web Standards in Dreamweaver ............................... 23
Authoring Valid XHTML ...................................................................................... 24 The Rules ofWriting XIITML ............................................................................ 26 Best Practices for Markup ................................................................................. 31
XHTML in Dreamweaver MX 2004 ...................................................................... 36 Setting Preferences ............................................................................................ 36
Authoring Valid CSS .......................................................................................... 37 Why Use CSS? .................................................................................................... 37 The Basics of CSS .............................................................................................. 40 Redefining How HTML Tags Look in the Browser ......................................... .42 Creating CSS Classes ......................................................................................... 42
CSS Tools in Dreamweaver MX 2004 ............................................................ .42 Setting Preferences ............................................................................................ 43 The CSS Panel .................................................................................................... 45 The Property Inspector ..................................................................................... 48 Design Files: Pre-Made CSS Stylesheets .......................................................... 50 Design Files: Page Designs (CSS) ..................................................................... 51 Design-Tinle Stylesheets .................................................................................. 52 Integration with TopStyle CSS Editor .............................................................. 53 Creating Valid Markup ...................................................................................... 53 The Layout ......................................................................................................... 58 Moving to XIITML Strict ................................................................................... 67
v
Contents
CSS for Layout ..................................................................................................... 72 Creating the Banner .......................................................................................... 73 Create the Navigation ....................................................................................... 75
The Content Area .............................................................................................. 79 Browser and Device Issues ............................................................................... 81
Working with Dynamic Data ............................................................................. 85
What to Watch Out For ...................................................................................... 85 Validating Dynanrlc Pages ................................................................................ 86
Summary .................................................................................................................... 86 Resources ................................................................................................................ 87
Chapter 3 Accessibility and Dreamweaver MX 2004 ........ 89
Accessibility Overview ................................................................................... 90 Why Is Accessibility Important? ....................................................................... 91 Defining Disabilities ......................................................................................... 93 Assistive Technologies ...................................................................................... 94 Accessibility Standards ..................................................................................... 95
Accessibility in Dreamweaver MX 2004 ..................................................... 99 Accessibility Preferences Options .................................................................... 99 Adding Images ................................................................................................. ] 00 Adding Media .................................................................................................. 1 02 Adding Frames ................................................................................................. l 03 Adding Forms .................................................................................................. ] 04 Adding Tables .................................................................................................. 106 Accessibility Validation .................................................................................. . 1 08 Accessibility Reference ................................................................................... 11 0 Cascading Style Sheets .................................................................................... lll Accessible Authoring Environment ............................................................... 112
Summary .................................................................................................................. 113
Chapter 4 Introducing ASP .............................................................. 115
No More Static ................................................................................................... 116 What's Wrong with HTML? ............................................................................. 116 Static vs. Dynamic ........................................................................................... 116
Exit Free CGI Hunting, Enter ASP ........................................................... 118 Getting Started ................................................................................................. 118
What You Need To Get Started ........................................................................ 119 Creating a Virtual Directory ............................................................................ 121 Setting Up Dreamweaver for ASP Development .......................................... 123
vi
Contents
ASPIVBScript Basics ........................................................................................ 124 Specifying Your Scripting Language .............................................................. 124 The Delirniters ................................................................................................. 124 Variables ........................................................................................................... 126 Writing Data to the Page ................................................................................. 129 Commenting Code .......................................................................................... 130 Concatenation Using the Ampersand(&) ..................................................... 131
Data Types: String, Integer, and Boolean ...................................................... 133 VBScript's House of Built-In Functions ......................................................... 134 Operators ......................................................................................................... 137 Conditional Logic ............................................................................................ 143 Controlling the Flow ofYour Programs .......................................................... 148
Applying Your ASP Knowledge ...................................................................... 150 Cool Web Forms .............................................................................................. 150 Dummy Login Form ........................................................................................ 151 Cookies (Not Made ofDough) ........................................................................ 157 Session Variables ............................................................................................. 162 Environment Variables ................................................................................... 165
Summary .................................................................................................................. 168 Resources .............................................................................................................. 169
Chapter 5 Databases Overview ....................................................... 171
How Do I Create a Database? ......................................................................... 171 Preparing a SQL Server Database for Internet Use ....................................... 175 Creating the IUSR Account in SQL Server ..................................................... 176 Database Design .............................................................................................. 178 Object Naming Conventions .......................................................................... 179 Creating Tables ................................................................................................ 180 Creating Tables Using Access ......................................................................... 181 Creating a Table in SQL Server ....................................................................... 183
Relational Databases and Referential Integrity ............................. 187 Creating a Relationship in Access ............................................................ ...... 188 Creating a Relationship in SQL Server ........................................................... 190 SQL Server Views and Access Queries ........................................................... 192
Simple SQL ............................................................................................................ 194 Selecting All Records from a Table ................................................................. 194
Selecting All Records That Meet One Criterion ............................................ 195 Selecting All Records That Meet Several Criteria ........................................ .. 196 Selecting Records That Meet One or More of Several Criteria ..................... 196 Useful SQL Keywords ...................................................................................... 197 Going on a DATE ............................................................................................. 205
vii
Contents
Making the Connection .................................................................................... 206
Setting Up a DSN to an Access Database ...................................................... 206
Setting Up a DSN to a SQL Server Database ................................................. 207
Connecting to Dream weaver MX 2004 ..... ..................................................... 208
The Simple Recordset Builder ........................................................................ 209
The Advanced Recordset Builder ................................................................... 214
Using Commands ............................................................................................ 217
Inserting a Record ........................................................................................... 219
Updating a Record ........................................................................................... 222
Updating Multiple Records (Simple Example) ............................................. 223
Deleting a Record ........................................................................... ................. 225
Deleting Multiple Records (Simple Example) ............................................... 226
Stored Procedures ........................................................................................... 227
The Stored Procedure Command .................................................................. 230
Summary .................................................................................................................. 231
Chapter 6 The Application Pane1 ............................................... 233
Connections ......................................................................................................... 233
Custom Connection String ............................................................................. 234
ODBC ............................................................................................................... 235
OLEDB ............................................................................................................. 235
Password-Protected Access Database ........................................................... 236 Connect to a Database .................................................................................... 236
System Data Source Name ............................................................................. 239
Bindings ................................................................................................................ 239
Request Variables ............................................................................................ 240
Creating Request Variables .................... ......................................................... 240
Creating Request Form Fields ..................................................................... ... 242
Creating Request Cookies ........................................................................... .... 242
Creating Request Server Variables ................................................................. 243
Creating Session Variables .............................................................................. 243
Server Behaviors .............................................................................................. 243
Recordset (Query) ............................................................................................ 244
Repeat Region ..................................................................................................... 246
Go to Detail Page ............................................................................................ 248
Master Page ...................................................................................................... 249
An Alternative Way to Generate a Master Page ............................................. 250
Detail Page ....................................................................................................... 253
Using Dynamic Images ................................................................................... 255
viii
Contents
Recordset Paging .............................................................................................. 258 Displaying a Few Records at a Time ............................................................... 258 Moving to Previous Record ............................................................................. 259 Moving to Next Record .................................................................................... 260
Show Region ......................................................................................................... 261 Show Region If Not First Record .................................................................... 261 Show Region If Not Last Record ..................................................................... 261 Recordset Navigation Bar ............................................................................... 262 Show Region If Recordset Is Empty ............................................................... 262 Show Region If Recordset Is Not Empty ........................................................ 263
Insert Record ..................................................................................................... 263 Using the Record Insertion Form WIZard ...................................................... 266
Update Record ..................................................................................................... 269 Delete Record ..................................................................................................... 273 User Authentication ........................................................................................ 275
Log In User ....................................................................................................... 275 Log Out User .................................................................................................... 279 Restrict Access to Page .................................................................................... 280 Check New Username ..................................................................................... 281
Summary .................................................................................................................. 284
Chapter 7 Code Reuse in Dreamweaver ..................................... 285
Dreamweaver Templates .................................................................................... 285 Creating a Simple Template ............................................................................ 286 Template Tips and Tricks ................................................................................ 294
Library Items ..................................................................................................... 296 Creating a Library Item ................................................................................... 297 Inserting a Library Item into Your Document ............................................... 299 Editing Library Items ...................................................................................... 299
ASP Includes ....................................................................................................... 301 A Basic Include ................................................................................................ 301 File or VIrtual Includes .................................................................................... 303 Using Includes for Items That Appear on Every Page .................................. 303 Templates vs. Includes .................................................................................... 307 Displaying Includes Conditionally ................................................................ 308
Snippets ................................................................................................................ 313 Snippets That Ship with Dreamweaver ......................................................... 313 Third-Party Snippets ....................................................................................... 317 Creating Your Own Snippets ........................................................................... 318
Summary .................................................................................................................. 320
ix
Contents
Chapter 8 Dreamweaver MX 2004 Extensions ........................ 32I
Finding Extensions .......................................................................................... 322
Installing Extensions ....................................................................................... 324
Importing Extensions ..................................................................................... 326
Building an Extension (or Two) ................................................................ 326
The Anatomy of an Extension ........................................................................ 327
The Extension Code ........................................................................................ 327
The Interface .................................................................................................... 328
Distributing Extensions ............................................................................... 335
Writing the MXI File ........................................................................................ 336
Packaging (from MXI to MXP) ........................................................................ 338
Distributing Your Extensions .......................................................................... 340
The Dynamic Web Address Server Behavior ............................................ 340
The Code .......................................................................................................... 340
Building the Server Behavior .......................................................................... 341
Editing the Interface ....................................................................................... 344
Add the Help Button ....................................................................................... 345
Summary .................................................................................................................. 346
Chapter 9 Debugging and Error Handling ............................. 347
Errors .................................................................................................................... 347 Viewing Error Messages .................................................................................. 347
ASP Errors-Script Errors ............................................................................... 348
ODBC Errors .................................................................................................... 354
SQL Errors ........................................................................................................ 358
Bugs ......................................................................................................................... 370
Re-Creating the Problem ................................................................................ 370
Coding to Avoid Bugs ...................................................................................... 372
Comment Your Code ....................................................................................... 372
Use Option Explicit ......................................................................................... 372
Naming Variables ............................................................................................ 374
Including Repeated Elements in Variables .................................................... 375
Display Errors on the Screen .......................................................................... 376
Where to Get Help ............................................................................................ 376
Web Resources ................................................................................................. 376
Newsgroups and Forums ................................................................................ 377
Summary .................................................................................................................. 378
X
Contents
Chapter 10 Final Case Study ............................................................ 379
Setting Up the Site ........................................................................................ 380 Configuring a Dreamweaver Site ................................................................... 380 Setting Up the Web Server .............................................................................. 381 TestingYour Setup ........................................................................................... 383 Building the Page Framework ........................................................................ 384
Creating a Database ........................................................................................ 386 Defining Tables ................................................................................................ 387 Setting Up a DSN ............................................................................................. 388 Defining a Connection .................................................................................... 388
Creating a Login Module ............................................................................... 389 Error Messages ................................................................................................ 390 Display Logic ................................................................................................... 391 Storing Login Details Using a Cookie ............................................................ 391
Assembling the Admin Pages ......................................................................... 392
User Management ........................................................................................... 393 Content Management ..................................................................................... 397
Constructing the Home Page ......................................................................... 398 Adding News Items ......................................................................................... 398
User Registration ............................................................................................ 400 Registration ...................................................................................................... 400
Editing User Details ...................................................................................... 402 Contact Form ....................................................................................................... 404 Summary .................................................................................................................. 405
Index .................................................................................................................... 407
xi
About the Authors
Rachel Andrew is a director of edgeofmyseat.com, aUK-based web solutions company, and is an experienced web developer. Rachel is a member of the Web Standards Project on the Dreamweaver Task Force, and she hopes to encourage best practices in the support and use ofW3C Standards in Dreamweaver. In addition to coauthoring several books, Rachel writes for various magazines and resource sites, both online and offline.
When not writing code or writing about writing code, Rachel spends time with her daughter, tries to encourage people to use Deb ian GNU /Linux, studies with the Open University, and enjoys a nice pint of beer.
Rob Turnbull is the senior developer for Lighthouse, an established new media design and marketing company based in Shrewsbury, England. Clients across Europe, from small businesses to blue-chip companies, provide an increasing workload, which includes the development of SQL Server database-driven web sites, multimedia presentations, interactive CD-ROMs, promotional videos and DVDs, and 3D artwork in both animated and still form.
Rob's personal web site, www. robgt. com, is primarily focused on offering help and guidance to fellow Dreamweaver users, including tutorials and links to helpful resources and some useful extensions.
Alan Foley is an assistant professor of instructional technology at North Carolina State University in Raleigh, North Carolina, where he teaches graduate classes in the College of Education. Alan holds a Ph.D. in educational technology from the University ofWisconsin-Madison. His current research interests include web accessibility and pedagogy, and accessible multimedia production.
Prior to completing his Ph.D., Alan was a high school English teacher. While teaching, he was introduced to the world of instructional technology and web design. He has taught web design in a variety of educational and corporate settings, and consults for schools and universities on accessibility and usability issues.
Drew McLellan is an experienced and knowledgeable web developer with over 7 years' experience designing and developing for the web. Among his strengths he counts a good awareness of design, team leadership, and the ability to communicate technical issues and concepts to nontechnical people. Drew is the author of Dream weaver MXWeb Development (New Riders, 2002).
xiii
About the Authors
xiv
Drew fights for standards in browsers and development tools with the Web Standards Project (www.webstandards.org), and he can often be found working on the sharp edge of his industry's technologies, always seeking to push the boundaries. He is an advocate of modular design and reusable code. Drew recently served a 4-year term as a Team Macromedia representative, and he has written a number of technical articles for www. macromedia. com and other online publications.
About the Technical Reviewer
A man of many talents, Matt Machell has been a web developer, technical editor, author, market researcher, and jewelry picker. He is currently freelancing and lurks on more web design-related discussion lists than is healthy. His personal web site is www. eclecticdreams. com. He lives in Birmingham, England, with his girlfriend, Frances, and lots of books.
XV
Acknowledgments
THANKs MUST GO TO the Apress team, to all those whose brains I have picked on mailing lists and Usenet over the years, to Drew for his constant love and support, and to my daughter Bethany.
Thank you, Rachel Andrew
xvii