Visual Web Developer 2005 Express Edition

Download as pdf or txt
Download as pdf or txt
You are on page 1of 244

Microsoft

Visual Web Developer

2005
Express Edition
Build a Web Site
A01622124.indd i 9/16/05 1:01:57 PM
PUBLISHED BY
Microsoft Press
A Division of Microsoft Corporation
One Microsoft Way
Redmond, Washington 98052-6399
Copyright 2006 by Microsoft Corporation
All rights reserved. No part of the contents of this book may be reproduced or transmitted in any form or by any means without the written permission
of the publisher.
Library of Congress Control Number 2005933641
Printed and bound in the United States of America.
1 2 3 4 5 6 7 8 9 QWT 9 8 7 6 5
Distributed in Canada by H.B. Fenn and Company Ltd.
A CIP catalogue record for this book is available from the British Library.
Microsoft Press books are available through booksellers and distributors worldwide. For further information about international editions,
contact your local Microsoft Corporation of ce or contact Microsoft Press International directly at fax (425) 936-7329. Visit our Web site
at www.microsoft.com/learning/. Send comments to [email protected].
Microsoft, Active Directory, FrontPage, Intellisense, Microsoft Press, MSDN, SharePoint, Visual Basic, Visual C#, Visual J#, Visual Studio,
Visual Web Developer, Windows, and Windows Server are either registered trademarks or trademarks of Microsoft Corporation in the United States
and/or other countries.
The example companies, organizations, products, domain names, e-mail addresses, logos, people, places, and events depicted herein are ctitious. No
association with any real company, organization, product, domain name, e-mail address, logo, person, place, or event is intended or should be inferred.
This book expresses the authors views and opinions. The information contained in this book is provided with out any express, statutory, or implied
warranties. Neither the authors, Microsoft Corporation, nor its resellers, or distributors will be held liable for any damages caused or alleged to be
caused either directly or indirectly by this book.
Acquisitions Editor: Ben Ryan
Project Editor: Sandra Haynes
Editorial and Production: Custom Editorial Productions, Inc.
Body Part No. X11-78002
A01622124.indd ii 9/16/05 1:01:59 PM
6[TcgXe$
<agebWhV\aZ@\VebfbYgI\fhT_JXU7XiX_bcXe
%##(8kceXff8W\g\ba $
what to xpect lrom This Book 2
Deciding whether VisuaI web DeveIoper is the
Product for You 3
what You'II Need for Testing 4
Choosing a Provider for Your PubIic web Site 5
DeaIing with lSO lmage liIes 7
Approaching the User lnterface 8
6[TcgXe%
CeXfXag\aZg[X4FC!A8G%!#CebZeT``\aZ
@bWX_ $&
loIIowing a web Page Through ASP.NT 2.0 l4
A Hierarchy o ConLrols 6
Dealing wiLh FvenLs 8
Reviewing Lhe Page Lie Cycle 9
Categorizing ASP.NT Server ControIs 20
6bagXagf
iii
6[TcgXe&
6eXTg\aZTAXjJXUF\gX %&
Choosing where to Put the working Copy
of Your Site 24
Creating an mpty web Site 25
CreaLing a File SysLem Web SiLe 25
CreaLing a Local llS Web SiLe 27
CreaLing a RemoLe llS Web SiLe 29
CreaLing an F1P-Accessible Web SiLe 8
6[TcgXe'
BcXa\aZTa8k\fg\aZJXUF\gX &(
Opening a kecentIy-Used web Site 36
Opening an Arbitrary web Site 37
Opening a File SysLem Web SiLe 87
Opening a Local llS Web SiLe 88
Opening an F1P-Accessible Web SiLe 89
Opening a RemoLe Web SiLe 40
6[TcgXe(
6bcl\aZLbheJXUF\gX '(
Specifying the Source and kemote web Sites 46
SeIecting and Copying liIes 47
X1146481A02.indd 3 9/14/05 10:06:11 AM
iv Microsoft VisuaI web DeveIoper 2005 xpress dition. BuiId a web Site Now!
6[TcgXe)
6eXTg\aZTaW@bW\Yl\aZJXUCTZXf ($
working with web Page Views 53
Adding ControIs 54
Adding ConLrols rom Lhe 1oolbox 54
Adding 1ables and Layers rom Lhe Menu 8ar 57
Adding ConLrols rom SoluLion Fxplorer 57
Setting ControI Properties 58
SeLLing ProperLies wiLh Lhe ProperLies Window 58
SeLLing ProperLies wiLh Lhe Mouse 6
SeLLing ProperLies wiLh SmarL 1ags 68
SeLLing ProperLies wiLh Lhe FormaL Menu 68
SeLLing ProperLies wiLh 1oolbars 64
Adding or Modifying HyperIinks 65
6[TcgXe*
Jbe^\aZj\g[FbheVX6bWX )*
Using the Text ditor 68
Using OuLlining 69
Using SpliL view 7
Using Co 1o, 8ookmarks, and Lhe 1ask LisL 72
Making Sense o lnLelliSense 78
DeLecLing SynLax Frrors 76
Finding and Replacing 1exL 77
FormaLLing Source Code 80
LocaLing More FdiLing Commands 82
Storing, CompiIing, and PubIishing Program Code 82
6[TcgXe+
6eXTg\aZTaWHf\aZJXUHfXe6bageb_f +(
Creating and Designing web User ControIs 86
Adding web User ControIs to a Page 88
Using web User ControIs ffectiveIy 90
UndersLanding Web User ConLrol 1ags 90
Using CSS SLyles in Web User ConLrols 9
AdjusLing RelaLive URLs 9
Coding ALLribuLes or Web User ConLrols 92
6[TcgXe,
Hf\aZ@TfgXeCTZXfgb6XageT_\mX
CTZX?Tlbhg ,(
Creating a Master Page 96
AppIying Master Pages to Content Pages l00
Using Master Pages ffectiveIy l03
Looking lnside MasLer Pages 04
Modiying FxisLing Pages Lo Use MasLer Pages 04
AdjusLing RelaLive URLs 06
Modiying Header lnormaLion 06
6[TcgXe$#
Hf\aZ6TfVTW\aZFgl_XF[XXgf $#*
lormatting Page Iements lndividuaIIy l08
Using Named StyIes Across SeveraI Pages l09
CreaLing a New SLyle SheeL File 09
CreaLing SLyle SheeL Rules 09
Adding ProperLies Lo SLyle SheeL Rules 2
Using Shared SLyles in our Web Pages 8
X1146481A02.indd 4 9/14/05 10:06:12 AM
6[TcgXe$$
6bageb__\aZ4ccXTeTaVXj\g[4FC!A8G
G[X`Xf $$(
Creating ASP.NT Themes ll6
Adding Skins to an ASP.NT Theme ll6
Adding CSS StyIe Sheets to an ASP.NT Theme ll9
AppIying Themes to Pages and Sites l20
6[TcgXe$%
?\a^\aZg[XCTZXf\aLbheF\gX
4hgb`Tg\VT__l $%(
Creating a Site Map for Your web Site l26
Creating Drop-Down and lIy-Out Menus l3l
Creating Tree View Menus l33
Providing Breadcrumbs l34
6[TcgXe$&
6eXTg\aZTaW6baaXVg\aZgb7TgTUTfXf $&*
Administering Data Access l38
Connecting to an xisting Database l38
Creating a New Database l42
Adding and Modifying Database TabIes l43
Viewing and Updating Database TabIe Content l46
6[TcgXe$'
7\fc_Tl\aZ7TgTUTfX<aYbe`Tg\ba $',
Using Data Sources l50
Configuring Data Sources l5l
DispIaying Database lnformation l55
Configuring a <g^YK^Zl ControI l57
TabIe of Contents v
6[TcgXe$(
@T\agT\a\aZ7TgTUTfX<aYbe`Tg\ba $)(
Using a <g^YK^Zl ControI to Update and
DeIete kecords l66
Using a 9ZiV^ahK^Zl ControI to Add kecords l69
6[TcgXe$)
ChU_\f[\aZLbhe7TgTUTfX $*&
Copying a SOL Server Database l74
Understanding and Connecting to SOL Server l75
Using ConnecLion SLrings 77
Sharing a Single Copy o SOL Server 82
AdminisLering Shared SOL Servers 82
Server lnsLances 82
User lnsLances 88
ALLaching DaLabase Files 84
UndersLanding Logins 84
How visual Web Developer Uses SOL Server 85
X1146481A02.indd 5 9/14/05 10:06:13 AM
X1146481A02.indd 6 9/14/05 10:06:20 AM
lntroduction vii
<agebWhVg\ba
CongraLulaLions on your inLeresL in MicrosoL visual Web
Developer 2005 Fxpress FdiLion. 1his exciLing new soLware
brings Lwo o MicrosoL's mosL powerul Lechnologies-
ASP.NF1 2.0 and visual SLudio 2005-wiLhin reach o anyone
who creaLes Web siLes.
visual Web Developer is a ully uncLional subseL o
visual SLudio 2005 suiLable or creaLing and mainLain-
ing a wide range o Web siLes over Lime. lL's cerLainly noL
a crippled or limiLed Lime demo version. lnsLead, iL's a key
MicrosoL iniLiaLive or bringing Lhe power o visual SLudio
and ASP.NF1 noL only Lo proessional programmers, buL Lo
hobbyisLs and enLrepreneurs as well.
who ls This Book lor?
1his book is primarily or people who've already designed
and deployed a Web siLe or Lwo, buL ound Lhe process or
Lhe Lools limiLing. For example, Lhey may have ound
eaLures such as Lhese diiculL Lo implemenL.
Q Reliable, reusable, and acLive page LemplaLes and page
segmenLs.
Q Fasy-Lo-use dynamic menus, expandable Lree views, or
breadcrumbs.
Q FasL, lexible, and easy ways o working wiLh daLabases.
Q ConLrolled access Lo porLions o a siLe, wiLh or wiLhouL
sel-regisLraLion.
ASP.NF1 2.0 has builL-in conLrols LhaL provide Lhese ea-
Lures and yeL, in many cases, require no program code aL all.
WhaL's more, you can add and conigure Lhese conLrols
enLirely Lhrough visual Web Developer's graphical inLerace.
visual Web Developer, like visual SLudio, has world class edi-
Lors or graphical design and or working wiLh code o all
kinds. lLs eaLures or working wiLh H1ML, CSS, and XML are
no less Lhan iLs power or working wiLh sophisLicaLed pro-
gram code.
l Lhis is Lhe kind o power you crave, or i you're ready
Lo advance rom legacy ASP Lo ASP.NF1 and need a place Lo
geL sLarLed, Lhis is Lhe book or you.
How This Book ls Organized
1he book consisLs o sixLeen chapLers plus Lwo bonus chap-
Lers on Lhe companion Web siLe. (See "8onus MaLerial"
below.) AlLhough each chapLer describes a speciic Lechnol-
ogy or eaLure, Lhe exercises do build on skills and resulLs
rom earlier in Lhe book. As a resulL, you should plan on
reading Lhe maLerial sequenLially.
Bonus MateriaI
1wo addiLional chapLers, ChapLer 7, 8dcigdaa^c\6XXZhhid
NdjgH^iZ and ChapLer 8, 9^heaVn^c\LZWEVgih! are provided
on Lhe companion Web siLe aL ]iie/$$lll#b^Xgdhd[i#Xdb$
bhegZhh$XdbeVc^dc$%",(*+"''&'")$.
X1146481A02.indd 7 9/14/05 10:06:27 AM
viii Microsoft VisuaI web DeveIoper 2005 xpress dition. BuiId a web Site Now!
Conventions and leatures in This Book
1his book presenLs inormaLion using convenLions designed Lo make Lhe inormaLion read-
able and easy Lo ollow. 8eore you sLarL Lhe book, read Lhe ollowing lisL, which explains
convenLions you'll see LhroughouL Lhe book and poinLs ouL helpul eaLures in Lhe book LhaL
you mighL wanL Lo use.
7cbjYbh]cbg
Q Fach exercise is a series o Lasks. Fach Lask is presenLed as a series o numbered sLeps
(, 2, and so on). Fach exercise is preceded by a procedural heading LhaL leLs you know
whaL you will accomplish in Lhe exercise.
Q NoLes labeled "1ip" provide addiLional inormaLion or alLernaLive meLhods or compleL-
ing a sLep successully.
Q NoLes labeled "CauLion" alerL you Lo inormaLion you need Lo check beore conLinuing.
Q 1exL LhaL you Lype or iLems you selecL or click appear in bold.
Q Menu commands, dialog box LiLles, and oLher user inLerace elemenLs appear wiLh each
word capiLalized.
Q A plus sign (-) beLween Lwo key names means LhaL you musL press Lhose keys aL Lhe
same Lime. For example, "Press AlL-1ab" means LhaL you hold down Lhe AlL key while
you press Lhe 1ab key.
Ch\Yf:YUhifYg
Q Shaded sidebars LhroughouL Lhe book provide more in-depLh inormaLion abouL Lhe
conLenL. 1he sidebars mighL conLain background inormaLion, design Lips, or eaLures
relaLed Lo Lhe inormaLion being discussed.
Q Fach chapLer ends wiLh an ln Summary. secLion LhaL briely reviews whaL you learned in
Lhe currenL chapLer and previews whaL Lhe nexL chapLer will presenL.
X1146481A02.indd 8 9/14/05 10:06:27 AM
System kequirements
ou'll need Lhe ollowing hardware and soLware Lo compleLe Lhe exercises in Lhis book.
Q MicrosoL Windows XP wiLh Service Pack 2, MicrosoL Windows Server 2008 wiLh Service
Pack , or MicrosoL Windows 2000 wiLh Service Pack 4
Q MicrosoL visual Web Developer 2005 Fxpress FdiLion
Q PC wiLh a PenLium lll-class processor, 600 MHz Recommended. CHz
Q 28 M8 RAM (256 M8 or more recommended)
Q 6.4 M8 hard disk space or sample iles
Q video (800 x 600 or higher resoluLion) moniLor wiLh aL leasL 256 colors (024 x 768 High
Color 6-biL recommended)
Q CD-ROM or DvD-ROM drive
Q MicrosoL Mouse or compaLible poinLing device
ou'll also need adminisLraLor access Lo your compuLer Lo conigure SOL Server 2005 Fxpress.
Obtaining the SampIe web Site
1o obLain a sample Web siLe incorporaLing Lhe examples, browse Lhe book's companion con-
LenL page aL Lhe ollowing address.
]iie/$$lll#b^Xgdhd[i#Xdb$bhegZhh$XdbeVc^dc$%",(*+"''&'")$
1o download and insLall Lhis siLe, ollow Lhe procedure LiLled, "1o ObLain And lnsLall Lhe
Sample Files For 1his 8ook," in ChapLer .
kunning the xercises and SampIe web Site
ASP.NF1 is a Lechnology LhaL runs primarily on a Web sever. ou'll need a Web server Lo LesL
and run Lhe examples in each chapLer, and o course Lhe compleLed sample Web siLe.
ForLunaLely, visual Web Developer comes wiLh iLs own inLegraLed DevelopmenL Web
Server. 8oLh Lhe exercises and Lhe compleLed sample Web siLe presume you'll be using Lhis
aciliLy. 1hereore, Lhere's no need Lo insLall or access a ull copy o lnLerneL lnormaLion
Server (llS).
VisuaI web DeveIoper's buiIt-in
web server is accessibIe onIy from
the IocaI computer. Any server
that deIivers the finished web site
wiII need a fuII copy of llS.
ABG 8
The CD-kOM packaged in the back
of this book contains the VisuaI
web DeveIoper 2005 xpress
dition software needed to com-
pIete the exercises in this book.
ABG 8
lntroduction ix
X1146481A02.indd 9 9/14/05 10:06:28 AM
1he exercises in ChapLers 8 Lhrough 6 (and ChapLers 7 and 8 on Lhe companion siLe)
require LhaL SOL Server 2005 Fxpress FdiLion (or SOL Server 2005) be insLalled on Lhe same
compuLer as visual Web Developer. l you insLall your soLware rom Lhe Companion CD, Lhis
will be Lhe deaulL. 8ecause Lhe exercises and sample Web siLe use a new SOL Server 2005
eaLure called jhZg^chiVcX^c\, no special securiLy coniguraLion is necessary.
kemoving the SampIe web Site
1o remove Lhe sample Web siLe rom your compuLer, ollow Lhese sLeps.
$ =b7cbhfc`DUbY`cdYb5XXCfFYacjYDfc[fUag"
%
:fcah\Y`]ghcZ7iffYbh`m=bghU``YXDfc[fUaggY`YWhA]WfcgcZhJ]giU`KYV8YjY`cdYf&$$)9ldfYgg
9X]h]cb.6i]`X5KYVG]hYBck
& 7`]W_FYacjY"
' :c``ckUbmZifh\Yf]bghfiWh]cbgh\UhUddYUf"
PrereIease Software
1his book was reviewed and LesLed againsL Lhe AugusL 2005 CommuniLy 1echnical Preview
(C1P) o visual SLudio 2005. 1he AugusL C1P was Lhe lasL preview beore Lhe inal release
o visual SLudio 2005. 1his book is expecLed Lo be ully compaLible wiLh Lhe inal release o
visual SLudio 2005. l Lhere are any changes or correcLions or Lhis book, Lhey'll be collecLed
and added Lo a MicrosoL Knowledge 8ase arLicle. See Lhe "SupporL or Lhis 8ook" secLion in
Lhis lnLroducLion or more inormaLion.
AIthough you can deveIop web
sites using SOL Server 2005
xpress dition, you, your lT
department, or your host wiII need
a fuII copy of SOL Server for deIiv-
ering the site to visitors.
ABG 8
x Microsoft VisuaI web DeveIoper 2005 xpress dition. BuiId a web Site Now!
X1146481A02.indd 10 9/14/05 10:06:28 AM
TechnoIogy Updates
As Lechnologies relaLed Lo Lhis book are updaLed, links Lo addiLional inormaLion will be
added Lo Lhe MicrosoL Press 1echnology UpdaLes Web page. visiL Lhis page periodically or
updaLes on visual SLudio 2005 and oLher Lechnologies.
]iie/$$lll#b^Xgdhd[i#Xdb$bhegZhh$jeYViZh$
Support for This Book
Fvery eorL has been made Lo ensure Lhe accuracy o Lhis book and Lhe companion conLenL.
As correcLions or changes are collecLed, Lhey'll be added Lo a MicrosoL Knowledge 8ase
arLicle. 1o view Lhe lisL o known correcLions or Lhis book, visiL Lhe ollowing arLicle.
]iie/$$hjeedgi#b^Xgdhd[i#Xdb$`W$.%*%)&
MicrosoL Press provides supporL or books and companion conLenL aL Lhe ollowing
Web siLe.
]iie/$$lll#b^Xgdhd[i#Xdb$aZVgc^c\$hjeedgi$Wdd`h$
Ouestions and Comments
l you have commenLs, quesLions, or ideas regarding Lhe book or Lhe companion conLenL, or
quesLions LhaL are noL answered by visiLing Lhe siLes above, please send Lhem Lo MicrosoL
Press via e-mail Lo
bhe^ceji5b^Xgdhd[i#Xdb
or via posLal mail Lo
MicrosoL Press
ALLn. visual Web Developer 2005 Fxpress FdiLion 8uild a Web SiLe Now FdiLor
One MicrosoL Way
Redmond, WA 98052-6899
Please noLe LhaL MicrosoL oers no soLware producL supporL Lhrough Lhese addresses.
lntroduction xi
X1146481A02.indd 11 9/14/05 10:06:28 AM
4Ubhgg[X4hg[be
Jim Buyens
Jim 8uyens has been proessionally involved wiLh Lhe
World Wide Web since iLs incepLion, including roles as a
server adminisLraLor, Web masLer, conLenL developer, sys-
Lem developer, and sysLem archiLecL. He has many years
o experience in Lhe LelecommunicaLions indusLry, and is
also an acclaimed MicrosoL MosL valuable Proessional
(MvP) who conLribuLes exLensively Lo Lhe MicrosoL Online
FronLPage CommuniLies.
Jim received a 8achelor o Science degree in CompuLer
Science rom Purdue UniversiLy in 97 and a MasLer o
8usiness AdminisLraLion rom Arizona SLaLe UniversiLy in
992. When noL enhancing Lhe Web or wriLing books,
he enjoys Lraveling and aLLending proessional sporLs
evenLs-especially NHL hockey. He resides wiLh his amily
in Phoenix.
OLher books by Jim 8uyens include.
Q MicrosoL Windows SharePoinL Services lnside OuL,
March, 2005, MicrosoL Press
Q MicrosoL Oice FronLPage version 2008 lnside OuL,
AugusL, 2008, MicrosoL Press
Q FasLer SmarLer 8eginning Programming, November,
2002, MicrosoL Press
Q Web DaLabase DevelopmenL SLep by SLep .NF1 FdiLion,
June, 2002, MicrosoL Press
Q 1roubleshooLing MicrosoL FronLPage 2002, May, 2002,
MicrosoL Press
Q MicrosoL FronLPage version 2002 lnside OuL, May,
200, MicrosoL Press
Q Web DaLabase DevelopmenL SLep by SLep, June, 2000,
MicrosoL Press
Q Running MicrosoL FronLPage 2000, June, 999,
MicrosoL Press
Q SLupid Web 1ricks, July, 998, MicrosoL Press
Q Running MicrosoL FronLPage 98, OcLober, 997,
MicrosoL Press
Q 8uilding NeL SiLes wiLh Windows N1-An lnLerneL
Services Handbook, July 996, Addison-Wesley
Developers Press
Dedication
1his book is dedicaLed Lo Lhe homeless menLally-ill persons
o America. Why do we lavish healLh care dollars on vicLims
o oLher, less debiliLaLing illnesses while condemning Lhese
unorLunaLes Lo Lhe sLreeLs and guLLers
xii Microsoft VisuaI web DeveIoper 2005 xpress dition. BuiId a web Site Now!
X1146481A02.indd 12 9/14/05 10:06:36 AM
l
6[TcgXe$
lntroducing Microsoft


Visuql Web Developer"
2005 Lxpress Ldition
CongraLulaLions on your inLeresL in MicrosoL visual Web Developer Fxpress
FdiLion. 1his incredible soLware makes iL very easy or hobbyisLs, enLhusiasLs,
and non-proessional Web developers Lo sLarL using MicrosoL ASP.NF1 2.0,
Lhe world's premier Lechnology or creaLing and running Web siLes.
Does Lhe idea o using ASP.NF1 scare you Well, wiLh Lhe arrival o ASP.
NF1 2.0, iL needn'L. AlLhough release 2.0 has many enhancemenLs LargeLed
primarily aL proessional programmers, iL also provides simple and eleganL
ways o implemenLing some o Lhe mosL challenging yeL popular eaLures
on Lhe Web-wiLhouL requiring a single line o program code! For example,
you can.
N CreaLe dynamic drop-down or ly-ouL menus.
N Surround Lhe variable conLenL on each page wiLh dynamic conLenL rom
a so-called mcster ce.
N Code a siLe map once and Lhen use iL Lo creaLe menus and breadcrumb
Lrails on each page.
N Ouery, creaLe, updaLe, and deleLe daLabase records.
N Close porLions o your siLe excepL Lo regisLered visiLors.
N LeL individual visiLors cusLomize Lhe way Lhey view your siLe. 1his includes
noL only Lhe siLe's visual appearance buL also-Lo Lhe exLenL you wanL-
Lhe layouL and conLenL o speciic pages.
&
Whqt to Lxpect
from This 8ook, 2
Deciding Whether Visuql
Web Developer is the
Product for You, J
Whqt You'll Need
for Testing, 4
Choosing q Provider for
Your Public Web Site, 5
Deqling with
lSO lmqge Files, 7
Approqching the User
lnterfqce, 8
C01622124.indd 1 9/9/05 9:31:07 AM
2 Microsoft VisuaI web DeveIoper 2005 xpress dition. BuiId a web Site Now!
AlLhough none o Lhis requires any program code, iL does require adding some special
XML Lags Lo your Web pages. 8uL even here, MicrosoL keeps Lhings simple. WiLh visual Web
Developer you can implemenL many ASP.NF1 eaLures (generally Lhe mosL popular ones) in
pure graphical design view. 1haL means no looking aL H1ML, no looking aL obscure XML
Lags, and cerLainly no looking aL program code.
O course, i you wanL Lo look aL (or even wriLe!) H1ML code, XML code, or program
code, visual Web Developer provides greaL ways o doing jusL LhaL. 8ecause iL's based on
MicrosoL visual SLudio

2005-Lhe premier environmenL or proessional programmers-


visual Web Developer Fxpress comes wiLh Lhe largesL, mosL powerul, and easiesL-Lo-use
selecLion o code ediLors you're likely Lo ind anywhere. And yes, i you sLarL a projecL in
visual Web Developer, you can conLinue iL in producLs like MicrosoL visual 8asic

.NF1
SLandard FdiLion, MicrosoL C# SLandard FdiLion, or any o Lhe ull visual SLudio producLs.
what to xpect lrom This Book
1his book assumes you're already amiliar wiLh Lhe basic workings o Lhe World Wide Web and
wiLh some Lypical Windows applicaLions such as MicrosoL Oice. For example, iL assumes you
know how Lo creaLe ordinary ("laL") H1ML pages and link Lhem inLo a Web siLe.
Fven Lhough visual Web Developer is a subseL o visual SLudio 2005 (a sophisLicaLed
programming Lool) Lhe book also assumes LhaL you Jcnt wanL Lo wriLe your own H1ML,
XML, or program code. lnsLead, Lhe book explains how Lo geL proessional ASP.NF1 2.0
resulLs using only Lhe graphical Web page ediLor.
l you Jc wanL Lo wriLe your own code, resL assured LhaL Lhe book will show you how Lo
view and modiy Lhe code LhaL Lhe graphical inLerace creaLes. 1he deLails o any code you
wriLe, however, will be up Lo you. l you wanL Lo learn abouL Lhe visual 8asic .NF1, C#, or J#
programming languages, abouL ASP.NF1, or abouL Lhe .NF1 ramework in general, you'll
need Lo ind a separaLe book on Lhe Lopic you wanL, or explore Lhe online inormaLion aL
htt.//msJn.micrcscft.ccm.
C01622124.indd 2 9/9/05 9:31:08 AM
Chapter l. lntroducing Microsoft VisuaI web DeveIoper 2005 xpress dition 3
Finally, Lhe book will concenLraLe on using eaLures new Lo ASP.NF1 2.0. Presumably,
Lhese are Lhe eaLures LhaL aLLracLed you Lo visual Web Developer in Lhe irsL place. As Lo
Lhe older eaLures, Lhe procedures or using Lhem are abouL Lhe same as or Lhe newer ones.
Once you undersLand using Lhe new eaLures, using Lhe older ones should be airly inLuiLive.
Deciding whether VisuaI web DeveIoper is the Product for You
MicrosoL designed visual Web Developer speciically or non-proessional programmers
who wanL Lo develop Web siLes LhaL use Lhe eaLures o ASP.NF1 2.0. l Lhis is your siLuaLion,
visual Web Developer is Lhe producL or you.
O course, no one producL can be besL or all people, and in all siLuaLions. Here are some
scenarios where oLher producLs mighL be a beLLer choice.
N ln Lheory, you could use visual Web Developer Lo creaLe Web siLes LhaL don'L use any
ASP.NF1 eaLures. 1haL is, you could use iL sLricLly as an H1ML ediLor. 1his, however,
orgoes Lhe sLrong poinLs o Lhe producL. l all you wanL is an H1ML ediLor, you mighL
preer a simpler producL dedicaLed Lo LhaL Lask.
N ln Lheory, you could also use visual Web Developer Lo creaLe ASP.NF1 . Web siLes. 1his,
however, would be diiculL because visual Web Developer won'L sLop you rom using
Lhe new eaLures in ASP.NF1 2.0. l you need Lo build Web siLes LhaL use ASP.NF1 .,
you'll probably ind iL easier Lo use MicrosoL visual SLudio 2008 or MicrosoL ASP.NF1
Web MaLrix.
N visual Web Developer can'L creaLe Windows deskLop applicaLions. l you need Lo creaLe
Windows applicaLions, obLain Lhe 2005 Fxpress FdiLion o visual 8asic, C#, C--, or J#,
graduaLe Lo Lhe SLandard version o Lhose languages, or invesL in a ull version o
visual SLudio.
;jgi]ZgGZVY^c\
1c lecrn mcre cbct ASP.Nl1
2.0. C=. viscl 3csic .Nl1. cr
SOl Server" lxress. ccnsiJer
these bccls frcm Micrcscft
Press

.
N Micrcscft viscl C= 200S
lxress lJiticn. 3ilJ c
Prcrcm Ncw!. bv Pctrice
PellcnJ
N Micrcscft ASP.Nl1 2.0
Prcrcmmin Ste 3v Ste.
bv Cecre SheherJ
N Micrcscft viscl 3csic 200S
Ste bv Ste. bv Michcel
Hclvcrscn
N Micrcscft viscl C= 200S
Ste bv Ste. bv Ichn Shcr
N Develcin Dctcbcse
Aliccticns with Micrcscft
SOl Server 200S lxress
Ste bv Ste. bv Icclie
CclJstein
C01622124.indd 3 9/9/05 9:31:08 AM
) B^Xgdhd[iK^hjVaLZW9ZkZadeZg'%%*:megZhh:Y^i^dc/7j^aYVLZWH^iZCdl
N Proessional and experL programmers are likely Lo need Lhe high-end Lools and eaLures
LhaL ull versions o visual SLudio provide. For example, MicrosoL visual SLudio 2005
Proessional FdiLion can creaLe many more kinds o soLware, and MicrosoL visual SLudio
2005 1eam SysLem has special eaLures LhaL supporL Leams o soLware developers work-
ing on Lhe same projecL.
L]ViNdjaaCZZY[dgIZhi^c\
AlLhough iL creaLes H1ML, CSS, and JavaScripL code LhaL runs on Lhe browser, ASP.NF1 is
primarily a server-side Lechnology. lL.
&# Reads Web pages and oLher iles rom Lhe Web server's ile sysLem.
'# Runs program code Lo access server-based resources and modiy Lhe currenL Web page.
(# Sends Lhe modiied Web page Lo Lhe visiLor.
As a resulL, Lo LesL an ASP.NF1 page you really need a Web server. l you have MicrosoL
lnLerneL lnormaLion Server (llS, MicrosoL's premier Web server) and ASP.NF1 2.0 insLalled on
your PC, you can cerLainly use Lhose resources or LesLing. 8uL i you don'L, visual Web Developer
will use iLs own builL-in mini-Web server. visual Web Developer sLarLs Lhis Web server Lhe irsL
Lime you browse or debug a page, and sLops iL when you quiL visual Web Developer.
visual Web Developer ully supporLs one and only one Lype o daLabase. MicrosoL SOL
Server. l Lhe prospecL o using SOL Server seems daunLing, consider Lhese acLs.
N visual Web Developer has ull builL-in graphical supporL or creaLing, viewing, modiying,
and deleLing SOL Server daLabases, Lables, and ields. As a resulL, you can perorm Lhese
Lasks wiLhouL using exLernal programs such as MicrosoL SOL FnLerprise Manager or
MicrosoL Access.
N ou don'L need Lo buy a copy o SOL Server or your own PC. SOL Server 2005 Fxpress
FdiLion is perecLly suicienL or developing your Web siLe, and iL's a ree download.
C01622124.indd 4 9/30/05 5:21:46 PM
Chapter l. lntroducing Microsoft VisuaI web DeveIoper 2005 xpress dition 5
N MicrosoL has made SOL Server daLabases as easy Lo upload as Access daLabases. 1he
enLire SOL Server daLabase resides in one ile (wiLh a .db ilename exLension) LhaL you can
upload Lo your hosLing provider. ln many cases, simply browsing your Web siLe will Lhen
cttcch your daLabase (LhaL, is make iL available) Lo Lhe copy o SOL Server LhaL services
your siLe. Providers who don'L supporL Lhis eaLure can iniLially aLLach Lhe daLabase or you.
Choosing a Provider for Your PubIic web Site
AlLhough visual Web Developer includes iLs own Web server, and alLhough SOL Server 2005
Fxpress is perecLly adequaLe or developmenL and LesLing, your producLion Web siLe will
need ull copies o.
N MicrosoL Windows 2000 Server or MicrosoL Windows Server" 2008.
N llS.
N ASP.NF1 2.0.
N MicrosoL SOL Server 2000 or MicrosoL SOL Server 2005.
l your currenL hosLing provider can'L supply all Lhese capabiliLies, you'll probably need Lo
ind a new provider. One place Lo look or a new provider is Lhe HosLers Providing ASP.NF1
page aL.
htt.//msJn.micrcscft.ccm/cs.net/infc/hcsters/Jefclt.csx
1he ollowing siLes may also be useul when searching or an ASP.NF1 2.0 hosLing provider.
N LocaLe a Web Presence Provider (MicrosoL FronLPage)
htt.//www.micrcscft.ccm/cffice/frcntce/rcJinfc/crtner/w.cs
N Windows HosL LisL (AuLomaLion 1ools, LLC)
htt.//www.winJcwshcstlist.ccm/hcstlist.csx
N Web HosLing Resource and DirecLory (AiniLy lnLerneL lnc.)
htt.//www.tchcsts.ccm/
L]ViVWdji6HE#C:I
LZWBVig^m4
ASP.Nl1 Web Mctrix is cn
nscrteJ tccl thct Micrcscft
relecseJ tc hel evclctcrs.
hcbbvists. cnJ enthsicsts et
stcrteJ bilJin ASP.Nl1 1.0
cnJ 1.1 cliccticns. lt hcs nc
Jirect relcticnshi tc cnv viscl
StJic rcJct.
viscl Web Develcer. bv
ccntrcst. is c Jirect member cf
the viscl StJic 200S fcmilv.
As c reslt. mch cf the scrt.
cttenticn. cnJ cJvice vc finJ
fcr viscl StJic will clv tc
viscl Web Develcer cs well.
Drin Jevelcment.
Micrcscft intercteJ mcnv cf
the lesscns lecrneJ. feeJbccl.
cnJ tc fectres frcm ASP.Nl1
Web Mctrix intc viscl Web
Develcer.
C01622124.indd 5 9/9/05 9:31:09 AM
6 Microsoft VisuaI web DeveIoper 2005 xpress dition. BuiId a web Site Now!
N WH1 HosL OuoLe (WebHosLing1alk.Com)
htt.//www.webhcstintcll.ccm/reqest.h
ou can, o course, search or a hosLing provider any way you like. MicrosoL inLends Lo
work wiLh hosLing providers so LhaL every Web developer or business can aord an ASP.NF1
2.0 Web siLe enhanced wiLh SOL Server.
OBTAlNlNG AND lNSTALLlNG VlSUAL wB DVLOPk
$
| yoJ |ave a CD |a cora|rs |e seJp ||es o \|sJa| \eb Deve|ope. pJ | |r yoJ CD d|ve ard
.a| o |e sp|as| sceer o appea C|e.|se. bo.se |pnsdrn|cosocondo.r|oads. seac|
o \|sJa| \eb Deve|ope |.pess. do.r|oad |e seJp pogan. ard Jr |
%
/dvarce |oJg| |e |rsa||a|or \|.ad's JsJa| ||cers|rg ard |rona|or sceers |verJa||y. ar
|rsa||a|or Cp|ors page |||e |e ore |r ||gJe 11 .||| appea
&
`oJ seJp op|ors nay vay
deperd|rg or |e ves|or o
\|sJa| \eb Deve|ope yoJ |ave. ard
deperd|rg or o|e so.ae |rsa||ed or
yoJ conpJe \|| ||s |r n|rd. Jse |e
gJ|de||res or |e re. page o se|ec |e
op|ors yoJ reed
'
C||c| |e Ne. bJor o conp|ee
|e |rsa||a|or
;^\jgZ&"&
G[XFgTegcTZXTccXTefj[XalbhbcXaI\fhT_JXU7XiX_bcXe!
You can run any combination of conventionaI HTML,
ASP, ASP.NT l.0, ASP.NT l.l, and ASP.NT 2.0 appIi-
cations on the same virtuaI web server. lf a particuIar
appIication isn't running under the version of ASP.NT
you want, an administrator can fIag the appIication to
run under the correct version.
< @C BEG4AG
C01622124.indd 6 9/9/05 9:31:10 AM
Chapter l. lntroducing Microsoft VisuaI web DeveIoper 2005 xpress dition 7
Microsoft MSDN 2005 xpress dition conLains exLensive help and oLher inormaLion
abouL ASP.NF1 2.0 and all Lhe Fxpress producLs. ou should almosL cerLainly insLall Lhis
opLion.
Microsoft SOL Server 2005 xpress dition provides a limiLed version o SOL Server
2005 LhaL you can use or developing your Web siLe. Unless you have (or plan Lo have) a ull
version o SOL Server 2005 running on your PC, you should insLall Lhis opLion.
DeaIing with lSO lmage liIes
l you download any o Lhe visual SLudio 2005 Fxpress producLs and receive a ile wiLh an
.iso or .img ilename exLension, Lhe ile is an lSO imce file. Such iles conLain Lhe exacL
represenLaLion o a CD or DvD.
N 1o copy an lSO image ile Lo a recordable CD, use a uLiliLy such as lSORecorder, Nero,
or Roxio.
N 1o exLracL an lSO image Lo a older on your disk, use a uLiliLy such as lSObusLer or
Daemon1ools.
N 1o map Lhe lSO image onLo an unused drive leLLer, use Lhe virLual CD-ROM ConLrol
Panel or Windows XP. 1o obLain Lhis soLware by ree download, reer Lo Lhe FAO page
ciLed below.
For more inormaLion on using Lhese producLs.
N 8rowse Lhe MSDN SubscripLions FrequenLly Asked OuesLions page aL
htt.//msJn.micrcscft.ccm/sbscriticns/fcq/Jefclt.csx
N Click MSDN Subscriber Downloads.
N Click Lhe quesLion, "WhaL are lSO image iles and how do l use Lhem"
C01622124.indd 7 9/9/05 9:31:11 AM
8 Microsoft VisuaI web DeveIoper 2005 xpress dition. BuiId a web Site Now!
TO OBTAlN AND lNSTALL TH SAMPL llLS lOk THlS BOOK
1he examples and exercises in Lhis book involve an imaginary Web siLe or ConLoso Magic,
an illusory supply shop or sLage magicians. 1o insLall Lhe compleLed Web siLe and daLabases
on your compuLer.
$
|rsa|| \|sJa| \eb Deve|ope ard a conpa|b|e
ves|or o SO| Seve as |e pev|oJs sec|or
|rsJced
%
Do.r|oad |e seJp pogan on htt.//
www.micrcscft.ccm/msress/ccmcnicn/
0-7JS6-2212-4/.
&
|Jr |e do.r|oaded seJp pogan o |rsa||
|e sanp|e ||es a \y DocJners\
\|coso |ess\\|sJa| \eb Deve|ope T|e \y
DocJners o|de JsJa||y es|des a C\DocJners
ard Se|rgs\Jserane>\\y DocJners
'
To oper |e |r|s|ed \eb s|e o C|apes 11b.
sa \|sJa| \eb Deve|ope. c|oose Cper \eb
S|e on |e ||e nerJ. ard spec|y |e s|e |oca|or as
\y DocJners\\|coso |ess\
\|sJa| \eb Deve|ope\Coroso\ag|c
To oper |e |r|s|ed \eb s|e o |e er|e boo|
(|rc|Jd|rg C|apes 1 ard 18). spec|y |e s|e
|oca|or as
\y DocJners\\|coso |ess\\|sJa| \eb
Deve|ope\Coroso\ag|c1
Approaching the User lnterface
1he irsL Lime you sLarL visual Web Developer, a display like Lhe one in Figure -2 will appear.
8ecause no projecL (LhaL is, no Web siLe) is open, many o Lhe rames and conLrols are
dimmed. NeverLheless, here's a brie rundown o Lhose LhaL appear by deaulL.
N 1he menu bar and Loolbars work exacLly like Lhose in MicrosoL Oice and oLher
MicrosoL programs. O course, Lhe commands are suiLed Lo Web siLe developmenL,
and noL Lo word processing or spreadsheeLs.
N 1he 1oolbox rame aL Lhe leL will conLain objecLs LhaL you can drag onLo an open
Web page. O course, Lhis requires LhaL boLh a projecL and a Web page be open.
N 1he SLarL Page in Lhe cenLer displays a lisL o projecLs you recenLly opened, a lisL o
LemplaLes you can use or sLarLing new projecLs, and some links Lo useul Web pages
on MicrosoL's Web siLe.
C01622124.indd 8 9/9/05 9:31:11 AM
Chapter l. lntroducing Microsoft VisuaI web DeveIoper 2005 xpress dition 9
N 1he SoluLion Fxplorer aL Lhe righL will display a lisL o Lhe iles and olders in an open
projecL.
N A DaLabase Fxplorer rame is Labbed behind Lhe SoluLion Fxplorer rame. 1his is where
you'll creaLe, modiy, and deleLe daLabases, Lables, and ields.
N 1he ProperLies rame will display an ediLable lisL o available properLies and currenL
seLLings or any objecL you selecL while, or example, ediLing a Web page.
1he menu bar, Lhe Loolbars, and all Lhe rames are dockable. 1haL means you can drag
Lhem away rom Lheir currenL posiLions along Lhe window border, park Lhem along anoLher
border, or leave Lhem loaLing. Again, Lhis works jusL like dockable rames in MicrosoL Oice.
Figure -8 shows how visual Web Developer looks when a projecL is open. 1he Loolbox
now shows a selecLion o conLrols, Lhe cenLer o Lhe window displays an open Web page
ready or ediLing, Lhe SoluLion Fxplorer shows Lhe iles and olders in Lhe projecL, and Lhe
ProperLies rame shows Lhe properLies and values or Lhe currenL elemenL (which happens Lo
be Lhe enLire documenL).
9\ZheX$%
BcXa\aZTceb]XVgeXiXT_fg[XYh__
cbjXebYI\fhT_JXU7XiX_bcXe!
C01622124.indd 9 9/9/05 9:31:12 AM
l0 Microsoft VisuaI web DeveIoper 2005 xpress dition. BuiId a web Site Now!
1he page in Lhe igure makes use o Lhese ASP.NF1 2.0 eaLures.
N 1he Lop, leL, and boLLom edges o Lhe Web page are dimmed because Lhey come rom a
mcster ce. in oLher words, rom a LemplaLe ile LhaL many oLher pages can incorporaLe
Lo ensure uniormiLy. ChapLer 9 will explain masLer pages.
1he masLer page in Lhe igure includes Lhese ASP.NF1 elemenLs.
;^\jgZ&(
BcXa\aZTceb]XVgeXiXT_fg[XYh__
cbjXebYI\fhT_JXU7XiX_bcXe!
N 1he area LhaL displays [LiLeral "liL8anner1iLle"] is
an ASP.NF1 litercl conLrol. One line o program
code reLrieves Lhe LiLle o Lhe currenL page and
copies iL inLo Lhe area where Lhis conLrol resides.
ChapLer 9 will explain Lhis Lechnique.
N 1he menu iLems Home, ProducLs, and Services
are Lhe Lop-level choices in a ly-ouL menu builL
auLomaLically rom a siLe map ile. ChapLer 2
explains menus and siLe map iles.
N 1he SiteMcDctcScrce conLrol provides daLa-
base-like access Lo Lhe siLe map ile. ChapLer 2
explains Lhese, Loo.
N 1he [UserNcmej conLrol shows Lhe name o Lhe
currenLly-logged-in user. ChapLer 7 will provide
more inormaLion abouL Lhis conLrol.
N 1he lcin conLrol generaLes a link Lo a page
where visiLors can log in or sel-regisLer.
ChapLer 7 explains how Lhis works.
N 1he area displaying rooL Node > ParenL Node > CurrenL Node is a SiteMcPcth conLrol.
1his conLrol looks in Lhe siLe map ile, inds Lhe URL o Lhe currenL page, and displays
a series o links back Lo Lhe home page. For more inormaLion abouL Lhis, consulL
ChapLer 2.
N 1he conLrol LiLled Ccntent - Ccntent1 (Cstcm} marks an area LhaL Lhe MasLer Page
leaves open or Lhe conLenL o individual pages. ChapLer 2 explains how Lhis works.
C01622124.indd 10 9/9/05 9:31:14 AM
Chapter l. lntroducing Microsoft VisuaI web DeveIoper 2005 xpress dition ll
N 1he senLence, "1his is Lhe ConLoso Magic home page," is variable conLenL unique Lo Lhe
DeaulL.aspx page.
l Lhis example seems overly conLrolled-wiLh so much conLenL coming rom a masLer
page-keep in mind LhaL Lhe designer chccses Lo work Lhis way. 1here's no requiremenL
Lo use masLer pages aL all, and no requiremenL Lo use any o Lhe oLher conLrols shown in
Lhe igure. However, Lhis page does illusLraLe Lhe power LhaL ASP.NF1 2.0 delivers Lo non-
programmers. Consider.
N 1he siLe map ile consisLs o simple, highly-repeLiLive XML sLaLemenLs like Lhis.
<siLeMapNode url="deaulL.aspx" LiLle="Home page" />
N 1he MasLer Page conLains one line o program code, Lhe one LhaL copies Lhe page LiLle
inLo Lhe page banner.
N OLher Lhan Lhese Lwo iLems, you can creaLe Lhis enLire page (or siLe) wiLhouL ever leaving
Lhe visual Web Developer graphical inLerace.
ln Summary.
visual Web Developer is a powerul Lool wiLh a simple graphical inLerace LhaL non-program-
mers and beginners can use Lo creaLe ASP.NF1 2.0 Web siLes.
ChapLer 2 will explain Lhe essenLials o ASP.NF1.
C01622124.indd 11 9/9/05 9:31:14 AM
C01622124.indd 12 9/9/05 9:31:14 AM
l3
6[TcgXe%
CeXfXag\aZg[X
4FC!A8G%!#
CebZeT``\aZ@bWX_
ASP.NF1 is a major componenL o MicrosoL's overall .NF1 iniLiaLive.
Compared Lo earlier Lechnologies like MicrosoL AcLive Server Pages (ASP)
and PHP HyperLexL Processor (PHP), ASP.NF1 is much broader, much more
powerul, and much more robusL. 8ecause o Lhese improvemenLs in ASP.
NF1, MicrosoL has designaLed AcLive Server Pages as a legacy Lechnology
LhaL will evenLually disappear.
Compared Lo earlier versions, ASP.NF1 2.0 provides many improvemenLs
in boLh power and ease o use. NeverLheless, all versions o ASP.NF1 deliver
Web pages in abouL Lhe same way. 1he nexL secLion will explain how Lhis
works. LaLer, anoLher secLion will describe Lhe basic Lypes o ASP.NF1 soLware
componenLs you can add Lo a Web page.
Keep in mind LhaL Lhis chapLer is only a brie inLroducLion Lo Lhese Lopics.
FnLire books have been wriLLen abouL Lhem. 1he maLerial in Lhis chapLer is
only enough Lo geL you sLarLed wiLh MicrosoL visual Web Developer".
l even Lhis inLroducLion seems a biL absLracL or diiculL, jusL skip ahead
Lo ChapLer 8. ou can always reer back laLer.
'
9b__bj\aZTJXUCTZX
g[ebhZ[4FC!A8G%!#$'
6TgXZbe\m\aZ4FC!A8G
FXeiXe6bageb_f%#
C02622124.indd 13 9/9/05 9:32:44 AM
l4 Microsoft VisuaI web DeveIoper 2005 xpress dition BuiId a web Page Now!
loIIowing a web Page through ASP.NT 2.0
For Lhe mosL parL, ASP.NF1 runs on a Web server. Fach Lime a Web visiLor requesLs a page
LhaL has an ASP.NF1 ile name exLension, such as .aspx, ASP.NF1.
l. Loads Lhe requesLed page inLo Lhe Web server's memory.
2. FxecuLes any ASP.NF1 soLware componenLs LhaL Lhe Web page conLains.
3. Sends Lhe resulLing page Lo Lhe Web visiLor.
When loading a Web page inLo memory, ASP.NF1 dierenLiaLes beLween Lwo very dierenL
kinds o conLenL.
N Ordinary HTML Tags are jusL LhaL. ordinary H1ML. ASP.NF1 does noLhing wiLh Lhese,
excepL Lo sLore Lhem and laLer LransmiL Lhem exacLly "as is." l, or example, your page
conLained Lhis Lag.
<1mg sc=1mages/my]ogo.g1f>
Lhen ASP.NF1 would send
<1mg sc=1mages/my]ogo.g1f>
Lo Lhe Web visiLors. 1he Web server doesn'L change ordinary H1ML aL all.
N ASP.NT Server ControIs are soLware componenLs LhaL ASP.NF1 loads inLo memory.
1he ollowing Lag, or example, Lells ASP.NF1 Lo load an Htmllmce server conLrol
inLo memory.
<1mg sc=1mages/my]ogo.g1f 1d=1mgMyLogo unaf=seve />
1he mosL imporLanL dierence beLween Lhis Lag and Lhe previous one is Lhe
rnct=server aLLribuLe, which Lells ASP.NF1 Lo creaLe a server conLrol on Lhe Web server.
ln addiLion.
N 1he Lag name (im in Lhis case) Lells ASP.NF1 whaL kind o server conLrol Lo creaLe.
N 1he iJ= aLLribuLe provides a name Lo which oLher server conLrols in Lhe same page
can reer.
C02622124.indd 14 9/9/05 9:32:45 AM
Chapter 2. Presenting the ASP.NT 2.0 Programming ModeI l5
N ASP.NF1 passes Lhe src= aLLribuLe (and any oLhers LhaL may be presenL) Lo Lhe server
conLrol as inpuL.
N 1he Lrailing slash saLisies Lhe XML requiremenL or an end Lag.
Once ASP.NF1 inishes loading a server conLrol, iL discards Lhe XML LhaL creaLed iL. When
iL's Lime Lo send Lhe page Lo Lhe visiLor, ASP.NF1 Jcesnt send Lhe server conLrol's original
XML Lag. lnsLead, iL calls a uncLion (or more correcLly, a methcJ) named RenJer LhaL's parL
o Lhe server conLrol, and Lhen, iL sends Lhe ouLpuL o LhaL meLhod Lo Lhe Web visiLor.
AlLhough all Lhe server conLrols LhaL come wiLh ASP.NF1 2.0 render Lheir ouLpuL as
H1ML, ASP.NF1 enorces no resLricLions on Lhe ouLpuL o a server conLrol's RenJer meLhod.
1he ouLpuL doesn'L have Lo resemble Lhe original XML Lag, and doesn'L even have Lo be
H1ML. For example, iL could be a picLure ile or a MicrosoL Word documenL.
1o summarize Lhe lie cycle o an ASP.NF1 page.
l. A visiLor requesLs a ile having an .aspx exLension.
2. ASP.NF1 reads Lhe ile rom Lhe server's ile sysLem.
3. ASP.NF1 inspecLs each Lag in Lhe ile and loads iL inLo memory.
N l Lhe Lag conLains a rnct=server aLLribuLe, ASP.NF1 loads a soLware componenL
called a server conLrol. 1he Lag name deLermines Lhe Lype o server conLrol.
N 1ags wiLh no rnct=server aLLribuLe are ordinary H1ML. ASP.NF1 loads Lhese inLo a
soLware componenL LhaL will, aL Lhe proper Lime, send Lhe original Lag Lo Lhe Web
visiLor verbaLim.
4. ALer loading all Lhe Lags inLo memory, ASP.NF1 execuLes designaLed program code wiLh-
in each server conLrol. 1his code can access resources on Lhe Web server, iL can change
Lhe conLenL or properLies o any server conLrol on Lhe page, and iL can even add or
remove oLher server conLrols.
ASP.NT treats aII server controI tags as XML, and therefore requires them to
have end tags. lf you don't want to code an expIicit end tag, as in
<1mg sc=myphofo.1pg unaf=seve></1mg>
code a sIash before the cIosing angIe bracket Iike this.
<1mg sc=myphofo.1pg unaf=seve />
G < C
very ASP.NT server controI has a
GZcYZg method.
ABG 8
C02622124.indd 15 9/9/05 9:32:46 AM
l6 Microsoft VisuaI web DeveIoper 2005 xpress dition BuiId a web Page Now!
5. When all Lhe code in all Lhe server conLrols inishes execuLing (LhaL is, when Lhe enLire
sLack o server conLrols comes Lo resL) ASP.NF1 sequenLially Lells each conLrol Lo renJer
iLsel (LhaL is, Lo supply whaLever H1ML Lhe visiLor should receive).
N l Lhe original Lag was ordinary H1ML, ASP.NF1 sends iL wiLhouL modiicaLion.
N l Lhe original Lag creaLed a server conLrol, ASP.NF1 calls Lhe conLrol's RenJer meLhod
Lo generaLe Lhe H1ML Lhe Web visiLor should receive.
6. Once Lhe page has leL Lhe server, ASP.NF1 releases iLs server conLrols and any oLher
resources iL may have creaLed.
A Hierarchy of ControIs
When ASP.NF1 loads server conLrols inLo memory, iL doesn'L sLore Lhem as a "laL" lisL.
lnsLead, iL sLores Lhem in a hierarchical Lree. 1his approach is quiLe ingenious, and iL illus-
LraLes Lhe power o ASP.NF1.
Fvery server conLrol has a Ccntrcls collecLion capable o holding addiLional server
conLrols. ln acL, Lhe ASP.NF1 page iLsel is a server conLrol. a Pce server conLrol. 1he Pce
conLrol uses iLs Ccntrcls collecLion Lo sLore a lisL o addiLional server conLrols. Fach o Lhose
conLrols has iLs own Ccntrcls collecLion LhaL can sLore more server conLrols, and so orLh.
1his hierarchy o conLrols is useul in siLuaLions like LhaL shown in Lhe ollowing code. A
<tcble> Lag conLains Lwo <tr> Lags, and Lhe <tr> Lags each conLain <tJ> Lags.
<fab]e 1d=fb]P]enfy unaf=seve>
<f 1d=oWP]enfyhead1ng unaf=seve>
<fd co]span=3 1d=ce]P]enfy11f]e unaf=seve></fd>
</f>
<f 1d=oWP]enfyDefa1] unaf=seve>
<fd 1d=ce]P]enfyAmounf unaf=seve></fd>
<fd 1d=ce]P]enfyun1f unaf=seve></fd>
<fd 1d=ce]P]enfyDesc1pf1on unaf=seve></fd>
</f>
</fab]e>
C02622124.indd 16 9/9/05 9:32:46 AM
Chapter 2. Presenting the ASP.NT 2.0 Programming ModeI l7
Presumably, all Lhis code would exisL wiLhin a Web page. 1he Lop o Lhe hierarchy would
Lhereore be a Pce conLrol. From LhaL poinL.
N 1he Ccntrcls collecLion in Lhe Page server conLrol would conLain Lhe Html1cble server
conLrol named tblPlentv.
N 1he Ccntrcls collecLion in Lhe HLml1able server conLrol would conLain Lwo Html1cbleRcw
server conLrols. rcwPlentvHecJin and rcwPlentvDetcil.
N 1he Html1cbleRcw server conLrol named rcwPlentvHecJin would have one iLem in iLs
ConLrols collecLion. Lhe Html1cbleCell server conLrol named celPlentv1itle.
N 1he Html1cbleRcw server conLrol named rcwPlentvDetcil would have Lhree iLems in
iLs ConLrols collecLion. Lhe Html1cbleCell server conLrols named celPlentvAmcnt,
celPlentvUnit, and celPlentvDescriticn.
When ASP.NF1 Lells Lhe page Lo render iLsel.
N 1he Pce conLrol Lells each member in iLs Ccntrcls collecLion Lo render iLsel aL Lhe
proper Lime. ln Lhis example, Lhe Pce conLrol would Lell Lhe tblPlentv server conLrol Lo
render iLsel.
N Fach conLrol (such as tblPlentv) LhaL has subordinaLe conLrols Lells Lhose subordinaLes Lo
render Lhemselves. For example, Lhe tblPlentv conLrol would Lell Lhe rcwPlentvHecJin
and rcwPlentvDetcil conLrols Lo render Lhemselves.
N Likewise, Lhe rcwPlentvHecJin would Lell Lhe celPlentv1itle conLrol Lo render iLsel and
inally Lhe rcwPlentvDetcil conLrol would Lell Lhe celPlentvAmcnt, celPlentvUnit, and
celPlentvDescriticn conLrols Lo render Lhemselves.
Program code can manipulaLe server conLrols, creaLe new ones, and deleLe any LhaL
aren'L appropriaLe Lo a parLicular requesL. For example, aLer reLrieving one row rom
a daLabase query, program code could creaLe an Html1cbleRcw objecL, append an
Html1cbleCell objecL Lo display each ouLpuL ield, and Lhen append Lhe Html1cbleRcw
objecL Lo Lhe exisLing Lable.
C02622124.indd 17 9/9/05 9:32:47 AM
l8 Microsoft VisuaI web DeveIoper 2005 xpress dition BuiId a web Page Now!
DeaIing with vents
ASP.NF1 server conLrols have a leeLing exisLence. 1he whole lie cycle o reading, execuLing,
and LransmiLLing an ASP.NF1 page consumes only racLions o a second. milliseconds or less.
NeverLheless, during LhaL racLion o a second, ASP.NF1 bombards each server conLrol
wiLh a series o messages called events. For each evenL, a given server conLrol may or may
noL have a maLching event hcnJler (which is a kind o uncLion or subrouLine). l a handler is
presenL, ASP.NF1 will run iL whenever Lhe given evenL occurs.
ASP.NF1 raises up Lo 80 evenLs or each server conLrol in a page. ForLunaLely, mosL
programmers, even advanced ones, seldom need Lo worry abouL all Lhese evenLs. 1able 2-
lisLs Lhe evenLs LhaL Web developers use Lhe mosL.
Among Lhese evenLs, Lhe Pce objecL's OnlccJ evenL is probably Lhe mosL useul. 1his evenL
occurs when ASP.NF1 has inished loading all Lhe page's server conLrols inLo memory, buL
beore ASP.NF1 has begun sending Lhe Web page Lo Lhe visiLor. 1his usually is Lhe perecL
Lime Lo perorm whaLever processing Lhe page requires.
Some ASP.NF1 server conLrols generaLe server-based evenLs in response Lo acLions LhaL
Lake place on Lhe browser. For example, clicking a buLLon or changing Lhe selecLion in a
drop-down lisL can.
N lniLiaLe a requesL Lo Lhe Web server.
N Re-execuLe Lhe same page.
IVWaZ'"&
6b``baFXeiXe6bageb_8iXagf
vent Occurs when
Onlnit ASP.NF1 iniLializes Lhe server conLrol.
OnlccJ ASP.NF1 inishes loading Lhe server conLrol.
OnPreRenJer ASP.NF1 is ready Lo sLarL asking server conLrols
Lo render Lhemselves.
OnUnlccJ ASP.NF1 is abouL Lo remove Lhe server conLrol
rom memory.
C02622124.indd 18 9/9/05 9:32:47 AM
Chapter 2. Presenting the ASP.NT 2.0 Programming ModeI l9
N Raise a special evenL LhaL relecLs Lhe buLLon click or change o selecLion.
N Run a cusLom-wriLLen evenL handler LhaL perorms whaLever processing Lhe evenL
requires.
1he acL LhaL ASP.NF1 wires each signiicanL browser evenL Lo a dierenL server-side
evenL handler is a greaL eaLure. lL Lruly simpliies Lhe Lask o ensuring LhaL Lhe righL code
runs in response Lo each evenL.
keviewing the Page Life CycIe
1his secLion inLroduced Lhe lie cycle o an ASP.NF1 page as iL passes Lhrough Lhe Web
server. lncorporaLing all Lhe deLails, here's how Lhis works.
N ASP.NF1 irsL reLrieves Lhe page rom Lhe server's ile sysLem and loads iL inLo memory. l
a Lag conLains a rnct=server aLLribuLe, ASP.NF1 loads a corresponding server conLrol.
OLherwise, iL saves Lhe Lag as ordinary H1ML and passes iL Lhrough unchanged.
N Program code in Lhe server conLrols runs in response Lo various evenLs, such as OnlccJ
and evenLs rom orm ields. 1his program code can access server-side resources and
change Lhe properLies o server conLrols as necessary.
N When all server conLrol evenL handlers have inished, ASP.NF1 asks each conLrol Lo
render iLsel and sends Lhe resulLs, in sequence, Lo Lhe Web visiLor.
N ConvenLional H1ML Lags go Lo Lhe visiLor unchanged.
N ln Lhe case o server conLrols, ASP.NF1 doesn'L send Lhe XML LhaL loaded Lhe
conLrol. lnsLead, Lhe conLrol's RenJer meLhod generaLes Lhe H1ML or oLher daLa
LhaL Lhe visiLor will receive.
N Once ASP.NF1 has senL Lhe enLire page Lo Lhe visiLor, iL relinquishes all Lhe objecLs LhaL
represenLed Lhe page.
C02622124.indd 19 9/9/05 9:32:47 AM
20 Microsoft VisuaI web DeveIoper 2005 xpress dition BuiId a web Page Now!
Categorizing ASP.NT Server ControIs
As wiLh almosL everyLhing in lie, Lhere are several way Lo caLegorize ASP.NF1 server conLrols.
1echnologically, Lhe caLegories are.
N web Custom ControIs reside enLirely wiLhin a DLL. Several projecLs or Web siLes can
Lhereore use a single copy o Lhe conLrol. 1his provides greaL assurance LhaL Lhe same
code is running in each o Lhose projecLs. However, Lo change Lhe conLrol you have Lo
locaLe Lhe original program code, change iL, recompile iL, and Lhen replace all copies o
Lhe resulLing DLL.
N web User ControIs consisL o an .ascx ile (which conLains a ragmenL o H1ML) and
eiLher source code iles or a DLL. Fach projecL or Web siLe LhaL uses a user conLrol musL
have iLs own copy o Lhese iles. 1his makes user conLrols easier Lo develop and modiy,
buL harder Lo keep in sync across mulLiple projecLs.
As a pracLical maLLer, i you're developing an ASP.NF1 server conLrol or use in one
projecL or Web siLe, iL's probably besL Lo develop a user conLrol. l you're developing a
conLrol or ongoing use in several projecLs or or sale as a producL, a cusLom conLrol is
probably Lhe beLLer choice.
ASP.NF1 provides a rich selecLion o server conLrols. 1hey're all Web cusLom conLrols, and
Lhey all wiLhin Lwo addiLional caLegories.
N HTML Server ControIs duplicaLe Lhe synLax and uncLion o LradiLional H1ML Lags.
AnyLime you sLarL wiLh a LradiLional H1ML Lag and add rnct=server, you're creaLing
an H1ML server conLrol.
New ASP.NF1 developers usually appreciaLe Lhese conLrols because o Lheir amiliar
synLax and because general-purpose Web design programs like MicrosoL FronLPage can
display Lhem accuraLely in graphical ediLing mode.
N web Server ControIs are more powerul Lhan H1ML server conLrols, buL use a com-
pleLely dierenL synLax.
9dNdj8jhidb^oZVJhZg
8dcigdadgJhZV8jhidb
8dcigda4
Mcnv new Jevelcers hcve
trcble rememberin the terms
Web cstcm ccntrcl cnJ Web
ser ccntrcl. 1c clcrifv the
Jistincticn. remember thct.
N Web cstcm ccntrcls
cJJress the neeJs cf mcnv
sers cnJ resiJe in c
sinle Dll.
N Web ser ccntrcls cre
ecsier fcr inJiviJcl Web
Jevelcers (sers} tc crecte
cnJ mcJifv.
Chapter 8 wiII expIain how to cre-
ate and use your own web user
controIs.
F 8 8 4? F B
C02622124.indd 20 9/9/05 9:32:48 AM
Chapter 2. Presenting the ASP.NT 2.0 Programming ModeI 2l
1he ollowing code, or example, creaLes an HtmlSelect conLrol LhaL displays a drop-down
lisL o conLinenLs.
<se]ecf 1d=se]Conf1nenf unaf=seve>
<opf1on va]ue=AI>Af1ca</opf1on>
<opf1on va]ue=A5>As1a</opf1on>
<opf1on va]ue=Au>Ausfa]1a</opf1on>
<opf1on va]ue=Lu>Luope</opf1on>
<opf1on va]ue=NA>Nofh Ame1ca</opf1on>
<opf1on va]ue=5A>5oufh Ame1ca</opf1on>
</se]ecf>
1he nexL block o code creaLes a DrcDcwnlist Web server conLrol LhaL renders an
idenLical drop-down lisL.
<asp:DopDoWnL1sf 1d=dd]Conf1nenf unaf=seve>
<asp:L1sflfem va]ue=AI>Af1ca</asp:L1sflfem>
<asp:L1sflfem va]ue=A5>As1a</asp:L1sflfem>
<asp:L1sflfem va]ue=Au>Ausfa]1a</asp:L1sflfem>
<asp:L1sflfem va]ue=Lu>Luope</asp:L1sflfem>
<asp:L1sflfem va]ue=NA>Nofh Ame1ca</asp:L1sflfem>
<asp:L1sflfem va]ue=5A>5oufh Ame1ca</asp:L1sflfem>
</asp:DopDoWnL1sf>
Why use Lhe more complex and less amiliar Web server conLrol One common reason
is LhaL only Lhe DropDownLisL Web server conLrol can generaLe evenLs on Lhe server. For
example, i you add Lhe aLLribuLes shown below in green Lo Lhe preceding Lag.
<asp:DopDoWnL1sf 1d=dd]Conf1nenf AufoPosf8ack=1ue
On5e]ecfedlndexChanged=dd]Conf1nenf5e]ecfedlndexChanged
unaf=seve>
C02622124.indd 21 9/9/05 9:32:48 AM
22 Microsoft VisuaI web DeveIoper 2005 xpress dition BuiId a web Page Now!
N 1he AtcPcst3ccl=1re aLLribuLe Lells Lhe conLrol Lo generaLe JavaScripL code LhaL
immediaLely submiLs Lhe page Lo Lhe Web server whenever Lhe visiLor selecLs a dierenL
conLinenL.
N 1he OnSelecteJlnJexChcneJ aLLribuLe Lells Lhe conLrol Lo run an evenL handler named
JJlCcntinent_SelecteJlnJexChcneJ whenever Lhe page goes ouL Lo Lhe browser and
comes back wiLh a dierenL conLinenL selecLed.
1haL evenL handler mighL, or example, reload a second DropDownLisL server conLrol
wiLh Lhe names o counLries in Lhe given conLinenL.
1he mosL powerul Web server conLrols abandon all semblance o convenLional H1ML
Lags. 1hey creaLe clickable calendars, drop-down or ly-ouL menus, siLe maps, breadcrumbs,
login buLLons, sel-regisLraLion orms, and a wide varieLy o addiLional useul prewriLLen
objecLs. All o Lhese, however, render Lhemselves as ordinary H1ML, and Lhereore work wiLh
any browser.
Chapter 8 wiII expIain how to add
and configure both HTML server
controIs and web server controIs
on any ASP.NT page.
G < C
ln Summary.
ASP.NF1 runs Web pages by loading Lhem inLo memory as a collecLion o ordinary H1ML
segmenLs and server conLrols. lL Lhen ires evenLs aL each server conLrol, causing designaLed
uncLions or subrouLines (evenL handlers) Lo run. Finally, ASP.NF1 geLs Lhe visiLor's H1ML by
calling each conLrol's RenJer meLhod.
1here are Lwo main Lypes o server conLrol. Web user conLrols are easier Lo develop, buL
Web cusLom conLrols are beLLer or widespread deploymenL.
ASP.NF1 comes wiLh Lwo kinds o builL-in server conLrols. H1ML server conLrols resemble
convenLional H1ML Lags in orm and uncLion. Web server conLrols require Lags wiLh liLLle
resemblance Lo ordinary H1ML, buL Lhey provide many specialized eaLures and Lhey do
send ordinary H1ML Lo Lhe browser. 1echnologically, boLh H1ML server conLrols and Web
server conLrols are Web cusLom conLrols.
1he nexL chapLer will explain how Lo work wiLh any program code LhaL your ASP.NF1
page requires.
C02622124.indd 22 9/9/05 9:32:49 AM
23
6[bbf\aZJ[XeXgb
Chgg[XJbe^\aZ6bcl
bYLbheF\gX%'
6eXTg\aZTa8`cgl
JXUF\gX%(
6[TcgXe&
6eXTg\aZTAXj
JXUF\gX
ln MicrosoL

visual Web Developer", as in general pracLice, a Web siLe is a


seL o Web pages and associaLed iles LhaL you inLend Lo creaLe, deploy, and
manage as a uniL.
l you like, you can choose Lo LreaL an enLire virLual Web server or
domain name as one Web siLe. FrequenLly, however, you'll have secLions o
conLenL LhaL you wanL Lo creaLe aL dierenL Limes, deploy aL dierenL Limes,
conLrol wiLh dierenL securiLy, or oLherwise manage separaLely. ForLunaLely,
wiLh ASP.NF1 2.0, you can begin a new siLe aL any older in your server's
conLenL Lree (LhaL is, in iLs URL space.)
(
There's no firm ruIe governing the size of an ASP.NT
2.0 web site. Most sites, however, have between severaI
dozen and severaI hundred web pages.
G < C
C03622124.indd 23 9/29/05 2:20:44 PM
24 Microsoft VisuaI web DeveIoper 2005 xpress dition. BuiId a web Page Now!
Choosing where to Put the working Copy of Your Site
MosL ASP.NF1 developers keep aL leasL Lwo copies o each siLe Lhey develop. a working
copy and a producLion copy.
N 1he working copy usually resides in an o-line or privaLe area, isolaLed rom Lhe
siLe's inLended audience. ALer all, Lhe working copy is work-in-progress. lL's probably
incompleLe and less Lhan ully uncLional. 1here's a recscn you're sLill working on iL.
N 1he producLion copy, or "live" siLe, resides on a Web server accessible Lo Lhe siLe's
audience. When Lhe working copy is inally, uh, working and approved, Lhe developer
or an adminisLraLor copies Lhe working copy Lo Lhe live siLe.
8ecause ASP.NF1 is a Lechnology LhaL runs program code on a Web server, you need a
Web server Lo LesL an ASP.NF1 Web siLe. FurLhermore, Lhe Web server needs Lo be running
ASP.NF1 2.0. ln general, Lhis presenLs Lwo choices.
N ou can use lnLerneL lnormaLion Server (llS), MicrosoL's premier Web server, insLalled
eiLher on your own compuLer or on a remoLe server.
N ou can use Lhe ASP.NF1 DevelopmenL Server builL inLo visual Web Developer. 1his is a
subseL o llS LhaL visual Web Developer sLarLs on demand, and LhaL runs unLil you quiL
visual Web Developer.
visual Web Developer supporLs inLeracLive debugging o any program code you
wriLe. 1haL means you can designaLe places where Lhe code should sLop and pause so
you can inspecL objecLs and variables, run Lhe program one sLaLemenL aL a Lime, and so
orLh. However, when Lhe debugger reezes your code, iL also musL reeze Lhe enLire Web
server and Lhis, o course, is upseLLing Lo anyone else using Lhe same server. 1o avoid such
problems, mosL ASP.NF1 developers debug on Lheir own compuLers, and noL on a server
Lhey share wiLh oLher people.
6a^\c^c\K^hjVaLZW
9ZkZadeZgH^iZhVcY
>>H6eea^XVi^dch
lven if vc Jevelc cnJ test
vcr Web site cn the
Develcment Server bilt intc
viscl Web Develcer. vcll
eventcllv neeJ tc rn it cn c
fll ccv cf llS. 1here cre twc
recscns fcr this.
N 1he Jevelcment server is
cnlv cccessible frcm vcr
cwn ccmter.
N llS is the cnlv fll-cccess
Web server thct scrts
ASP.Nl1 2.0.
Unfcrtnctelv. llS Jcesnt
JiviJe c Web server intc sites
the scme wcv thct viscl Web
Develcer Jces. lnstecJ. llS
JiviJes Web servers intc
cliccticns. ln essence.
N A site is c fclJer tree thct
viscl Web Develcer
mcnces cs c nit.
N An cliccticn is c fclJer
tree thct llS mcnces cs
c nit.
6bag\ahXWbaaXkgcTZX
The ASP.NT DeveIopment Server works onIy IocaIIy. lt
can't serve pages to another computer. lt's onIy suitabIe
for testing pages on your own computer.
< @C BEG4AG
C03622124.indd 24 9/29/05 2:20:46 PM
Chapter 3. Creating a New web Site 25
Creating an mpty web Site
ou can locaLe Lhe working copy o an ASP.NF1 Web siLe in our kinds o places.
N A ile sysLem locaLion, such as a older on your compuLer's hard disk or a shared neLwork
older.
N An llS server running locally on your compuLer.
N An llS server running remoLely (LhaL is, on anoLher compuLer on your neLwork).
N An llS server wiLh a ile sysLem accessible via F1P.
1he ollowing secLions will describe Lhese opLions in more deLail and explain how Lo
creaLe a new Web siLe in each case.
Creating a liIe System web Site
ln a ile sysLem Web siLe, you can sLore Lhe iles or your Web siLe in any ile sysLem older
you like. 1his can be on your local compuLer or in a neLwork ile sharing locaLion. 1able 8-
summarizes Lhe advanLages and drawbacks o Lhis approach.
lts imcrtcnt thct these
twc fclJer trees bein ct the
scme fclJer. Otherwise. vcr
viscl Web Develcer site wcnt
rn rcerlv cn llS. 1here cre
three wcv cf flcin vcr sites
rcct fclJer cs cn llS cliccticn.
N lf vc blish the site
bv sin the Micrcscft
lrcntPce

Server
lxtensicns. the server exten-
sicns will flc the sites rcct
fclJer cs cn llS cliccticn.
N ln the Micrcscft llS Mcncer
cJministrctive tccl riht-
clicl the sites stcrtin fclJer.
chccse Prcerties. cnJ then
cn the Directcrv tcb. nJer
Aliccticn Settins. clicl
the Crecte bttcn. lf vc
Jcnt hcve ermissicn tc
Jc this vcrself. ccntcct the
servers scrt stcff.
N lcter in this chcter. c sec-
ticn titleJ Crectin c lcccl
llS Web Site exlcins hcw tc
flc fclJers cs llS cliccticns
withct lecvin viscl Web
Develcer. Hcwever. this
reqires the scme ermis-
sicns cs sin llS Mcncer.
6bag\ahXWYeb`cTZX%'
IVWaZ("&
4WiTagTZXfTaW7eTjUTV^fbYT9\_XFlfgX`JXUF\gX
Advantages
ou don'L need Lo have a ull copy o
llS running on your compuLer. lnsLead,
you can LesL pages by using Lhe ASP.NF1
DevelopmenL Server.
ou don'L need adminisLraLive righLs Lo
creaLe or debug local Web siLes.
1he ASP.NF1 developmenL server is only
accessible rom Lhe local compuLer. 1his
may reduce securiLy vulnerabiliLies.
Drawbacks
ou can'L LesL cerLain advanced eaLures o
llS-such as H11P-based auLhenLicaLion,
applicaLion pooling, and lSAPl ilLers-on
Lhe ASP.NF1 DevelopmenL Server.
Co-workers can'L preview Lhe siLe direcLly
rom your compuLer. 1o permiL previewing,
you'd have Lo publish Lhe siLe Lo a server
running llS.
C03622124.indd 25 9/29/05 2:20:47 PM
26 Microsoft VisuaI web DeveIoper 2005 xpress dition. BuiId a web Page Now!
|r |e |argJage dopdo.r ||s bo.. se|ec |e \eb s|e's deaJ| pogann|rg |argJage
C||c| C? \|sJa| \eb Deve|ope ceaes |e s|e. opers a deaJ| page |r |e page des|gre. ard d|s
p|ays |e o|de |r So|J|or |.p|oe
l Lhe paLh you speciied already conLains iles, visual Web Developer prompLs you Lo
speciy a dierenL older name, open Lhe exisLing Web siLe, or creaLe Lhe Web siLe anyway.
ln Lhe lasL case, iles rom Lhe LemplaLe you selecL will overwriLe any like-named iles LhaL
already exisL.
TO CkAT A llL SYSTM wB SlT lN VlSUAL wB DVLOPk
;^\jgZ("&
G[\fW\T_bZUbk\fg[X_ThaV[cb\agYbe
VeXTg\aZTaXjJXUf\gX\aI\fhT_JXU
7XiX_bcXe!
C|oose BYkKYVG]hY on |e |||e nerJ
\|er |e Ne. \eb S|e d|a|og bo. s|o.r |r
||gJe `1 appeas. se|ec a enp|ae |r |e
Tenp|aes bo. |o e.anp|e. c|oose /S|N|T
\eb S|e
|r |e |oca|or |e|d
Q Se|ec :]`YGmghYa |r |e dopdo.r ||s bo.
Q Type. se|ec. o bo.se o |e ||e sysen |oca|or
yoJ .ar
$
%
&
(
'
C03622124.indd 26 9/29/05 2:20:49 PM
Chapter 3. Creating a New web Site 27
IVWaZ("'
4WiTagTZXfTaW7eTjUTV^fbYT?bVT_<<FJXUF\gX
Advantage
ou can LesL all llS eaLures including H11P-
based auLhenLicaLion, applicaLion pooling,
and lSAPl ilLers.
1he siLe is accessible rom oLher compuLers.
(However, iL's your responsibiliLy Lo ensure
LhaL only Lhe people you wanL have access.)
Drawbacks
ou musL have adminisLraLive righLs Lo
creaLe or debug llS Web siLes.
Only one user on Lhe compuLer can debug
llS aL a Lime.
Local llS Web siLes have remoLe access
enabled by deaulL. 1his may noL be
appropriaLe in some siLuaLions.
Creating a LocaI llS web Site
Local llS Web siLes run using a copy o llS insLalled on your compuLer. Fach Web siLe runs as
iLs own llS applicaLion. visual Web Developer updaLes iles by using Lhe FronLPage server
exLensions or by accessing Lhe ile sysLem direcLly. 1able 8-2 summarizes Lhe advanLages and
drawbacks o Lhis approach.
1o creaLe a local llS Web siLe, you musL irsL saLisy Lhese requiremenLs.
N ou musL be logged onLo your compuLer wiLh adminisLraLor privileges. Only an adminis-
LraLor can modiy Lhe necessary llS seLLings.
N llS musL be insLalled on your compuLer and musL be running.
N ASP.NF1 2.0 musL be insLalled on Lhe compuLer and enabled in llS.
1he iles in a local llS Web siLe can reside anywhere you like. Here are some examples.
N ou can creaLe a new siLe under Lhe llS rooL (Lypically C.\lneLPub\wwwrooL) and mark iL
as an llS applicaLion.
N ou can creaLe a new siLe aL any older locaLion on your compuLer, Lhen Lell visual Web
Developer Lo mark iL as boLh an llS virLual direcLory and an llS applicaLion.
N ou can creaLe a Web siLe LhaL poinLs Lo an exisLing llS applicaLion, and Lhen ediL Lhe iles
in LhaL applicaLion.
C03622124.indd 27 9/29/05 2:20:50 PM
28 Microsoft VisuaI web DeveIoper 2005 xpress dition. BuiId a web Page Now!
TO CkAT A LOCAL llS wB SlT
C|oose BYkKYVG]hY on |e |||e nerJ
\|er |e Ne. \eb S|e d|a|og bo. appeas. se|ec ary enp|ae ||sed |r |e Tenp|aes bo.
Se|ec |TT| |r |e |oca|or dopdo.r ||s bo.
| yoJ .ar o |ardype |e re. s|e's |||. |ocae |'s ||es |r
|e \eb Seve's JsJa| corer space (o e.anp|e. .|||r
C\|re|Jb\...oo). ard na|e |e s|e ar ||S app||ca|or. poceed
as o||o.s
QType |e re. ||| |ro |e |oca|or Te. bo. |o e.anp|e. ype
htt.//lccclhcst/CcntcscMcic.
QS||p o sep
C|e.|se. a|e |ese seps
QC||c| |e |o.se bJor T||s d|sp|ays |e C|oose |oca|or d|a|og
bo. s|o.r |r ||gJe `
QC||c| |e |oca| ||S |cor o d|sp|ay |e ||s o |oca| \eb seves
(
| yoJ .ar |e re. \eb s|e o Jse ||es on ar e.|s|rg ||S app||ca|or. se|ec |e o|de .|ee |e
e.|s|rg app||ca|or beg|rs. c||c| |e Cper bJor. ard |er s||p o sep
)
|r |e bo. ||ed Se|ec T|e \eb S|e `oJ \ar To Cper. se|ec |e \eb seve ard |er. | recessay.
|e paer o|de o |e s|e yoJ .ar o ceae |o e.anp|e. | yoJ .ar o ceae a s|e a doves
.||e. se|ec doves
*
| yoJ .ar |e re. \eb s|e's ||es o es|de .|||r |e \eb seve's JsJa| corer space. Jse |e
C|oose |oca|or d|a|og bo. as o||o.s
QC||c| |e Ceae Ne. \eb /pp||ca|or bJor T||s |s |e |s o |ee bJors |a appea rea |e op
|g| core o |e d|a|og bo.
;^\jgZ("'
G[\fW\T_bZUbkW\fc_TlfT_\fgbY_bVT_
JXUfXeiXefTaWg[X\eHE?fcTVXf!
HfX\ggbfX_XVgg[XcTeXagYb_WXebYg[X
aXjJXUf\gXlbhjTaggbVeXTgX!
$
%
&
'
C03622124.indd 28 9/29/05 2:20:52 PM
Chapter 3. Creating a New web Site 29
Q/ re. o|de raned \ebS|e .||| appea |r |e Se|ec T|e \eb S|e `oJ \ar To Cper bo. |erane ||s
o|de o |e rane yoJ .ar
| yoJ .ar |e re. \eb s|e's ||es o es|de e|se.|ee. a|e |ese seps
QC||c| |e Ceae Ne. \|Ja| D|ecoy bJor T||s |s |e n|dd|e bJ
or |a appeas rea |e op |g| core o |e C|oose |oca|or
d|a|og bo. C||c||rg | d|sp|ays |e Ne. \|Ja| D|ecoy d|a|og bo.
s|o.r |r ||gJe ``
Q|r |e /||as Nane bo.. ype |e ||| pa| .|ee yoJ .ar |e re. s|e
o es|de
Q|r |e |o|de bo.. ype o bo.se o |e p|ys|ca| |oca|or .|ee |e \eb s|e ||es .||| es|de
QC||c| C| o ceae |e v|Ja| d|ecoy
C||c| |e CdYb bJor o ceae |e s|e |r ||S
Se|ec |e \eb s|e's deaJ| pogann|rg |argJage
C||c| C? o ceae |e s|e ard oper | |r \|sJa| \eb Deve|ope
l Lhe paLh you speciied already conLains iles, visual Web Developer will display a warn-
ing prompL.
Creating a kemote llS web Site
A remoLe Web siLe uses a copy o llS insLalled on anoLher compuLer LhaL you can
access over a neLwork. our Web siLe iles reside on Lhe remoLe compuLer and visual Web
Developer communicaLes wiLh Lhe Web siLe via Lhe FronLPage Server FxLensions. 1able 8-8
presenLs Lhe advanLages and disadvanLages o Lhis approach.
1o creaLe a remoLe llS Web siLe requires Lhe ollowing.
N 1he remoLe compuLer musL be running Lhe 2.0 version o Lhe .NF1 Framework.
N 1he remoLe compuLer musL have llS insLalled and running.
;^\jgZ("(
G[\fW\T_bZUbkWXY\aXfTYb_WXe\ag[X
JXUfXeiXefHE?fcTVXTaWTffbV\
TgXf\gj\g[Tc[lf\VT_Y\_X_bVTg\ba!
+
,
$#
C03622124.indd 29 9/29/05 2:20:53 PM
30 Microsoft VisuaI web DeveIoper 2005 xpress dition. BuiId a web Page Now!
N ASP.NF1 musL be enabled in llS on Lhe remoLe compuLer.
N 1he FronLPage Server FxLensions musL be insLalled and enabled aL Lhe rooL level where
you're creaLing Lhe siLe.
N ou musL have FronLPage adminisLraLion or auLhor permissions Lo creaLe new olders and
iles on Lhe remoLe compuLer.
TO CkAT A kMOT llS wB SlT
C|oose BYkKYVG]hY on |e |||e nerJ
\|er |e Ne. \eb S|e d|a|og bo. appeas. se|ec a enp|ae |a appeas |r |e Tenp|aes bo.
|r |e |oca|or |e|d. se|ec <HHD |r |e dopdo.r ||s bo.
/ yoJ d|sce|or o||o. ore o |ese pocedJes
Q Type |e re. s|e's ||| |ro |e |oca|or bo. |o e.anp|e. ype htt.//www.excmle.ccm/
CcntcscMcic
Q C||c| |e 6fckgY bJor. se|ec FYachYG]hY. |er ype |e ||| yoJ .ar |ro |e \eb S|e
|oca|or bo.
IVWaZ((
4WiTagTZXfTaW7eTjUTV^fbYTEX`bgX<<FJXUF\gX
Advantage
ou can LesL Lhe Web siLe in Lhe same
environmenL as Lhe producLion server (or,
i you eel lucky, direcLly on Lhe producLion
server).
MulLiple developers can work on Lhe same
siLe aL Lhe same Lime
Drawbacks
Coniguring Lhe shared server or
debugging can be complex.
Only one developer can debug Lhe
applicaLion aL a Lime. ln addiLion, Lhe
server suspends all oLher requesLs while Lhe
developer is sLepping Lhrough code.
$
%
&
'
C03622124.indd 30 9/29/05 2:20:54 PM
Chapter 3. Creating a New web Site 3l
Q C||c| |e 6fckgY bJor. se|ec FYachYG]hY. c||c| |e BYkKYVG]hY bJor. ard |er ype |e ||| yoJ
.ar |ro |e \eb ||| bo.
Se|ec |e \eb s|e's deaJ| pogann|rg |argJage
C||c| C? o ceae |e s|e ard oper | |r \|sJa| \eb Deve|ope
visual Web Developer creaLes Lhe siLe, opens a deaulL page in Lhe page designer, and
displays Lhe older in SoluLion Fxplorer. l Lhe paLh you speciied already conLains iles, visual
Web Developer prompLs you Lo speciy a dierenL locaLion.
Creating an lTP-AccessibIe web Site
On some Web servers, Lhe only way Lo updaLe iles is by using File 1ranser ProLocol
(F1P). 1his is oLen Lhe case on servers provided by commercial hosLing services. visual Web
Developer supporLs Lhis environmenL. Speciically.
N Whenever visual Web Developer needs Lo read or wriLe a ile, iL does so via F1P.
N l Lhe F1P locaLion is also wiLhin Lhe conLenL Lree o an llS Web server running ASP.NF1
2.0, you can run and LesL your siLe rom Lhe same server.
1able 8-4 summarizes Lhe advanLages and drawbacks o an F1P-accessible Web siLe.
(
)
Advantage
ou can direcLly open, LesL, and modiy
your siLe on Lhe producLion Web server
Drawbacks
ou can'L creaLe an llS applicaLion by F1P.
l you work only on Lhe F1P server, you
have no backup copies o Lhe siLe. Unless
you Lake oLher precauLions, Lhe F1P copy is
Lhe only copy.
8esL pracLice is Lo LesL your siLe beore iL
goes inLo producLion, and Lhen publish Lhe
LesLed siLe by F1P.
IVWaZ(")
4WiTagTZXfTaW7eTjUTV^fbYTa
9GC4VVXff\U_XJXUF\gX
C03622124.indd 31 9/29/05 2:20:55 PM
32 Microsoft VisuaI web DeveIoper 2005 xpress dition. BuiId a web Page Now!
1o use Lhis approach, Lhe siLe you wanL Lo open musL be available on an F1P server and
you musL geL Lhe ollowing inormaLion rom Lhe F1P server adminisLraLor.
N 1he name o Lhe F1P server where you wanL Lo open Lhe Web siLe.
N 1he name o Lhe F1P older where you have permission Lo creaLe and wriLe iles.
ou mighL also need.
N A user name and password or Lhe server.
N 1he porL number LhaL Lhe F1P server uses. 1his is Lypically porL 2.
TO CkAT AN lTP-ACCSSlBL wB SlT
C|oose BYkKYVG]hY on |e |||e nerJ
\|er |e Ne. \eb S|e d|a|og bo. appeas. se|ec a enp|ae on |e Tenp|aes bo.
|r |e |oca|or |e|d. se|ec :HD |r |e dopdo.r ||s bo.
| yoJ .|s|. ype o se|ec |e s|e's |T| |oca|or (sJc| as |ppe.anp|econpJb||c_|n|
Coroso\ag|c) C|e.|se. c||c| |e 6fckgY bJor ard na|e sJe |e |T| S|e |cor |s se|eced T|e
C|oose |oca|or d|a|og bo. .||| esenb|e ||gJe `4
|||| |r |e o||o.|rg |e|ds. |er c||c| CdYb
Q Server |re |e rane o |e seve. sJc| as ft.//ft.excmle.ccm.
Q Port | |e |T| seve opeaes or a po o|e |ar 1. c|arge ||s va|Je
Q Directory Type |e rane o |e |T| o|de .|ee yoJ .ar |e \eb s|e ||es o es|de (T||s oer d|
es on |e |TT| o|de. ard on |e p|ys|ca| ||e sysen o|de as .e||) |o e.anp|e. a|| |e o||o.|rg
n|g| po|r o |e sane p|ys|ca| ||e |oca|or
|T| o|de rane blic_html/CcntcscMcic/
|TT| o|de rane Coroso\ag|c
|||e sysen o|de rane C.\lnetPb\wwwrcct\CcntcscMcic\
Q Passive Mode Se|ec ||s bo. | yoJ |ave oJb|e connJr|ca|rg .|| |e |T| seve becaJse o a
|e.a||
when VisuaI web DeveIoper cre-
ates a web site via lTP, it can't
perform the necessary step of
configuring the web site as an
llS appIication. lnstead, you or a
server administrator must use the
llS Manager administrative tooI to
configure the appIication.
< @C BEG4AG
$
%
&
'
(
C03622124.indd 32 9/29/05 2:20:56 PM
Chapter 3. Creating a New web Site 33
Q Anonymous Login Se|ec ||s bo. | |e |T| seve pen|s
ead|rg ard .||rg ||es .||oJ |ogg|rg |r C|ea | | yoJ reed
o ere a Jse rane ard pass.od
Q User Name and Password |re ceder|a|s |a pov|de |e
recessay access o yoJ |T| ||e aea T|ese n|g| d|e on
yoJ JsJa| \|coso \|rdo.s

|og|r ceder|a|s
Se|ec |e \eb s|e's deaJ| pogann|rg |argJage
C||c| C? o ceae |e s|e ard oper | |r \|sJa| \eb
Deve|ope
visual Web Developer connecLs Lo Lhe F1P server and
copies Lhe LemplaLe iles Lo LhaL locaLion. Don'L orgeL
LhaL or new siLes, you or a server adminisLraLor need Lo
run Lhe llS Manager adminisLraLive Lool and mark Lhe siLe
as an applicaLion.
ln Summary.
lL's good pracLice Lo have aL leasL Lwo copies o any Web siLe you mainLain. a developmenL
or "working" copy and a producLion or "live" version. visual Web Developer can mainLain
working copies in our kinds o places. in a ile sysLem locaLion, on a local llS server, on a
remoLe llS server, or on an F1P-accessible server. 1he live siLe will usually reside on a remoLe
llS server
1he nexL chapLer will explain how Lo open exisLing siLes.
;^\jgZ(")
J[XaVbaaXVg\aZgbTa9GCf\gXg[X6[bbfX?bVTg\baW\T_bZ
Ubkcebi\WXfg[XfXbcg\baf
)
*
C03622124.indd 33 9/29/05 2:20:58 PM
C03622124.indd 34 9/29/05 2:20:58 PM
35
BcXa\aZTEXVXag_lHfXW
JXUF\gX&)
BcXa\aZTa4eU\geTel
JXUF\gX&*
|o|e 4
BcXa\aZTa
8k\fg\aZJXUF\gX
Web siLes are decidedly high-mainLenance. ou creaLe Lhem once and Lhen
you mainLain Lhem orever. As a resulL, you'll probably open exisLing siLes
much more oLen Lhan you creaLe new ones. ForLunaLely, MicrosoL

visual
Web Developer" makes opening siLes o eiLher Lype very easy. 1his chapLer
explains Lhe procedures you need Lo ollow.
)
C04622124.indd 35 9/9/05 9:35:55 AM
36 Microsoft VisuaI web DeveIoper 2005 xpress dition. BuiId a web Site Now!
Opening a kecentIy-Used web Site
When visual Web Developer sLarLs up, iL displays Lhe SLarL Page shown previously in
Figure -2. On Lhe SLarL Page, Lhe RecenL ProjecLs box conLains a clickable lisL o Web siLes
you recenLly opened. 1o open one o Lhese siLes again, simply click on iL. When Lhe SoluLion
Fxplorer window shows an expandable lisL o Lhe iles and olders in Lhe siLe, Lhe siLe is open.
1he same lisL o recenL siLes appears on Lhe File menu. 1o open a siLe LhaL way, choose
RecenL ProjecLs rom Lhe File menu, Lhen click on Lhe siLe you wanL rom Lhe resulLing
submenu.
8y deaulL, visual Web Developer remembers Lhe lasL 0 siLes you open. l you wanL iL Lo
remember more or ewer siLes, proceed as ollows.
TO kMMBk MOk Ok lwk SlTS
C|oose Cdh]cbg on |e Too|s nerJ
%
\|er |e Cp|ors d|a|og bo. appeas. |ocae |e
S|o. /|| Se|rgs c|ec| bo. |r |e boon |e core
ard na|e sJe |'s se|eced
&
|r |e ee v|e. a |e |e o |e d|a|og bo.. oper |e
|rv|orner rode ard se|ec ;YbYfU` T|e d|a|og
bo. .||| |er esenb|e ||gJe 41
'
|r |e |ecer |||es aea. |ocae |e e. bo. ||ed
=hYagG\ckb=bFYWYbh`mIgYX@]ghgard ype |e
rJnbe o s|es yoJ .ar \|sJa| \eb Deve|ope o enen
be
C||c| C?
;^\jgZ)"&
V|:o| e| |eve|ce cv|Je o
m/|oJ c| .c||o:o||c c||c |e
e.cJ |ex| |cx .c|c| ||e |eo|| c|
e.e||/ :eJ |||
ln ligure 4-l, the text box titIed
ltems Shown ln windows Menu
specifies the maximum number
of window names that VisuaI web
DeveIoper wiII dispIay after you
cIick window on the main menu.
ABG 8
$
(
C04622124.indd 36 9/9/05 9:35:56 AM
Chapter 4. Opening an xisting web Site 37
Opening an Arbitrary web Site
1o open any exisLing Web siLe, regardless o wheLher you opened iL recenLly or noL, proceed
as ollows.
TO OPN AN AkBlTkAkY wB SlT
C|oose CdYbKYVG]hYon |e |||e nerJ
%
\|er |e Cper \eb S|e d|a|og bo. s|o.r
|r ||gJe 4 appeas. c||c| |e |cor |r |e
||aces ba (or |e |e) |a bes desc|bes yoJ
s|e's |oca|or
&
Cor|rJe as d|eced |r |e re. oJ sec|ors
T|ee's ore sec|or o eac| c|o|ce |r |e
||aces ba
;^\jgZ)"'
|| ve|c c| ||e (e e| '||e J|o|co
|cx |e| /c: e|e.| o ||e o..e|||e v|o ||e
||.cc|| |Jcw

|||e /|em
Opening a liIe System web Site
ALer you click Lhe File SysLem icon in Lhe Open Web SiLe dialog box, Lhe display should
resemble LhaL shown in Figure 4-2.
$
C04622124.indd 37 9/9/05 9:35:57 AM
38 Microsoft VisuaI web DeveIoper 2005 xpress dition. BuiId a web Site Now!
TO OPN A llL SYSTM wB SlT
$
|r |e Cper \eb S|e d|a|og bo.. oper o c|ose ary recessay ee rodes. |er |ocae ard se|ec |e
o|de |a cora|rs |e oo o yoJ \eb s|e
C||c| |e CdYb bJor
1here's jusL one precauLion. 9dci use Lhe Open Web SiLe command Lo open a older LhaL
isn'L Lhe rooL o a Web siLe. 1his usually happens when you have a complex older Lree and.
N Some olders wiLhin LhaL Lree are Web siLe rooL olders.
N Some olders are jusL subolders wiLhin a siLe.
When you use Lhe Open Web SiLe command Lo open a older, visual Web Developer
assumes LhaL older will be Lhe rooL o a Web siLe, and LhaL iL'll be an llS applicaLion, and
LhaL iL's OK Lo sLore specially-named ASP.NF1 coniguraLion iles and subolders Lhere. l
Lhose assumpLions aren'L Lrue, Lhe siLe won'L work as you expecL. So again, whenever you
use Lhe Open Web SiLe command, make sure you're opening a Web siLe's rooL older.
Opening a LocaI llS web Site
l you click Lhe Local llS icon in Lhe Open Web SiLe dialog box, Lhe display will change Lo
Lhe orm shown in Figure 4-8.
1his is essenLially Lhe same view o Lhe Web server's URL space LhaL Lhe llS Manager
adminisLraLive Lool displays.
Two of the fiIes that must
reside in the root of an ASP.
NT web site are web.config
and web.sitemap. The spe-
ciaI subfoIders bin, App_Code,
App_Data, App_GIobaIkesources,
App_LocaIkesources, App_
webkeferences, App_Browsers,
and App_Themes must aIso reside
in the site's root foIder.
ABG 8
%
C04622124.indd 38 9/9/05 9:35:57 AM
Chapter 4. Opening an xisting web Site 39
TO OPN A LOCAL llS wB SlT
$
|ocae |e o|de |a cora|rs |e oo o yoJ \eb s|e
To do ||s. oper o c|ose ary ee rodes as recessay
Se|ec |e o|de ard c||c| |e CdYb bJor
NoLice LhaL in Figure 4-8, Lwo o Lhe older icons
(>>H=Zae and bV\^X) depicL an open carLon wiLh a globe
and a documenL inside. l a older has Lhis icon, iL's Lhe
rooL o an llS applicaLion. 1hese rooL olders are Lhe ones
you should open in visual Web Developer.
l you Lry Lo open a older LhaL's noL Lhe rooL o an llS
applicaLion, visual Web Developer will display a warning
message and ask i you wanL Lo conLinue. ln almosL every
case, Lhe correcL answer is No. 1hen, Lo recover.
N l Lhe older you Lried Lo open is parL o anoLher appli-
caLion, open LhaL applicaLion.
N l Lhe older you Lried Lo open h]djaY be Lhe rooL o
an llS applicaLion, selecL iL and click Lhe CreaLe New
Web ApplicaLion buLLon (Lhe leLmosL o Lhree in Lhe
Lop righL corner o Lhe dialog box).
Opening an lTP-AccessibIe web Site
l you click Lhe F1P SiLe icon in Lhe Open Web SiLe dialog box, Lhe display will change Lo Lhe
orm shown previously in Figure 8-4.
TO OPN A wB SlT ACCSSlBL ONLY BY lTP
;^\jgZ)"(
|e /c: ce o |c.o| ||' e| ||e. ||e (e e| '||e J|o|co |cx J||o/ ||| v|ew
c| ||e e| eve J|| o.e
$
|||| oJ |e |e|ds as |e sec|or ||ed 'Cea|rg ar |T|/ccess|b|e
\eb S|e' |r C|ape ` |rsJced yoJ
C||c| |e CdYb bJor
%
%
C04622124.indd 39 9/9/05 9:35:58 AM
40 Microsoft VisuaI web DeveIoper 2005 xpress dition. BuiId a web Site Now!
As when creaLing an F1P-accessible Web siLe, iL's your job Lo ensure LhaL Lhe F1P locaLion
you speciy corresponds Lo Lhe rooL o an llS applicaLion on Lhe Web server.
Opening a kemote web Site
l you click Lhe RemoLe SiLe icon in Lhe Open Web SiLe dialog box, Lhe display will change
Lo resemble Figure 4-4.
;^\jgZ)")
|e /c: ce o emc|e e| ||e.
||ee c |cwe ||| |c |e| /c: ||J
||e .ce.| e| eve oJ o||
TO OPN TH kMOT wB SlT
Type |e \eb s|e's J|| ||| |r |e \eb S|e |oca|or bo. /|era|ve|y. c||c| |e Ne. \eb S|e bJor
ard ceae a s|e as |e sec|or ||ed 'Cea|rg a |enoe ||S \eb S|e' |r C|ape ` |rsJced
C||c| |e CdYb bJor
$
%
C04622124.indd 40 9/9/05 9:35:59 AM
Chapter 4. Opening an xisting web Site 4l
When opening a remoLe Web siLe in visual Web Developer, you should be aware o
Lhese precauLions.
N 1he siLe will only be accessible i Lhe MicrosoL FronLPage

Server FxLensions are


insLalled on Lhe Web server. visual Web Developer uses Lhe FronLPage Server FxLensions
Lo read and wriLe iles on Lhe server, Lo modiy Web server seLLings, and Lo oLherwise
inLeracL wiLh Lhe Web server..
N 1he older you speciy should be Lhe rooL o a FronLPage Web siLe and Lhe rooL o an llS
applicaLion. 1his will normally be Lhe case or any Web siLes you creaLe in visual Web
Developer or in a ull version o MicrosoL visual SLudio

.
l, or some reason, Lhe locaLion isn'L Lhe rooL o a FronLPage Web siLe, and you Y^Y
speciy Lhe correcL older, converL Lhe older inLo a FronLPage server-based Web siLe
using eiLher Lhe MicrosoL FronLPage Server FxLension AdminisLraLion Web pages on Lhe
Web server or MicrosoL FronLPage.
l you speciy Lhe correcL locaLion and ind iL isn'L Lhe rooL o an llS applicaLion, use Lhe
MicrosoL llS Manager adminisLraLive Lool Lo mark Lhe older as an applicaLion, Lhen Lry
opening iL again.
N 1he llS applicaLion should be conigured Lo use ASP.NF1 2.0. l iL isn'L, visual Web
Developer displays a warning message and asks i you wanL Lo proceed. ln almosL every
case, you should.
. Answer No Lo Lhe prompL.
2. Make sure version 2.0 o Lhe .NF1 Framework is insLalled on Lhe remoLe compuLer.
8. Make sure Lhe llS applicaLion is conigured Lo use ASP.NF1 2.0.
4. 1ry again Lo open Lhe applicaLion in visual Web Developer.
llS can run any combinaLion o ASP.NF1 .0, ., and 2.0 applicaLions on Lhe same virLual
Web server.
C04622124.indd 41 9/9/05 9:36:00 AM
42 Microsoft VisuaI web DeveIoper 2005 xpress dition. BuiId a web Site Now!
TO CHCK Ok CONllGUk TH VkSlON Ol ASP.NT lOk AN APPLlCATlON
Sa |e ||S \arage adn|r|sa|ve oo|
|r |e |e pare o |e ||S \arage app||ca|or. oper
Q T|e rode o |rere |rona|or Sev|ces
Q T|e rode o |e conpJe |r oJes|or
Q T|e \eb S|es rode
Q T|e rode o |e v|Ja| seve |r oJes|or (|e DeaJ| \eb S|e)
Q T|e rode o ary paer o|des yoJ reed o oper so yoJ ||S app||ca|or's oo o|de |s v|s|b|e
||g|c||c| yoJ app||ca|or's oo o|de. |er c|oose DfcdYfh]Yg on |e esJ||rg s|ocJ nerJ
\|er |e app||ca|or's |ope|es d|a|og bo. appeas. c||c| |e 5GD"B9H ab T|e d|a|og bo. s|oJ|d
|er esenb|e ||gJe 4'
Se |e /S|N|T ves|or dopdo.r ||s o |e nos ecer ves|or o /S|N|T J |rsa||ed or |e
seve. |er c||c| |e C? bJor
$
%
&
'
(
C04622124.indd 42 9/9/05 9:36:00 AM
Chapter 4. Opening an xisting web Site 43
ln Summary.
visual Web Developer provides several dierenL ways o opening an exisLing Web siLe.
1wo o Lhese are Lhe RecenL ProjecLs lisL and Lhe Open Web SiLe command on Lhe File menu.
Using Lhese commands, visual Web Developer can open Web siLes LhaL reside aL a ile
sysLem paLh, on a local llS server, on a remoLe server accessible by F1P, or on a remoLe server
running Lhe FronLPage server exLensions..
1he nexL chapLer will explain how Lo copy a siLe rom place Lo place (or example, rom a
live producLion siLe Lo a work area, or vice versa).
;^\jgZ)"*
|| J|o|co |cx |cm ||' |oooe .c||o:e
||e ve|c c| /'||| ||o| o ||' o||.o||c
w||| :e
C04622124.indd 43 9/9/05 9:36:01 AM
C04622124.indd 44 9/9/05 9:36:01 AM
45
FcXV\Yl\aZg[XFbheVXTaW
EX`bgXJXUF\gXf')
FX_XVg\aZTaW6bcl\aZ
9\_Xf'*
6[TcgXe(
6bcl\aZLbhe
JXUF\gX
Any Lime you have mulLiple copies o a Web siLe-such as a working copy
and a live producLion copy-iL's cerLain LhaL rom Lime Lo Lime you'll need
Lo copy one or more iles rom one locaLion Lo anoLher, or even copy Lhe
enLire siLe! For example, you may wish Lo sLarL a new working copy based on
your live siLe, or you mighL need Lo copy compleLed changes rom Lhe work-
ing copy Lo Lhe producLion siLe.
MicrosoL

visual Web Developer" has builL-in eaLures LhaL make Lhis


easy, and Lhis chapLer explains how Lhose eaLures work.
*
C05622124.indd 45 9/9/05 9:41:45 AM
46 Microsoft VisuaI web DeveIoper 2005 xpress dition. BuiId a web Site Now!
TO COPY A SlT lkOM ON LOCATlON TO ANOTHk
Sa \|sJa| \eb Deve|ope
Cper ore s|e as d|eced |r C|ape 4
C|oose 7cdmKYVG]hY on |e \ebs|e nerJ T||s d|sp|ays |e Copy \eb .|rdo. s|o.r |r
||gJe '1
Q Source web Site T||s aea occJp|es
|e |e s|de o |e .|rdo. | s|o.s |e
corers o |e s|e yoJ opered |r sep 1
Q kemote web Site T||s aea occJp|es
|e |g| s|de o |e .|rdo. |r||a||y. |
nay be b|ar| |r gerea|. |oJg|. |
s|o.s |e corers o |e o|e s|e
|rvo|ved |r |e copy opea|or |y
deaJ|. ||s |s |e enoe \eb s|e yoJ
opered nos ecer|y
Desp|e |ese aeas be|rg raned SoJce
ard |enoe. re||e d|sarce ro d|ec
|or na|e ary d|eerce |o e.anp|e
Q T|e soJce s|e coJ|d be |a| .ay
aoJrd |e .o|d ard |e enoe s|e
coJ|d be or yoJ o.r conpJe
Q `oJ car copy ||es on enoe o
|oca| as eas||y as on |oca| o enoe
| |e SoJce ard |enoe aeas d|sp|ay
|e coec pa| o \eb s|es. s||p o |e
re. sec|or |r ||s c|ape C|e.|se.
cor|rJe o sep 4
Specifying the Source and kemote web Sites
;^\jgZ*"&
G[X6bclJXUYXTgheXW\fc_Tlfg[XVbagXagfbYgjbJXUf\gXfTaWVbc\XfTalY\_Xflbh_\^XUXgjXXag[X`!
$
%
&
C05622124.indd 46 9/9/05 9:41:46 AM
Chapter 5. Copying Your web Site 47
'
Cper |e 7cbbYWh]cbg dopdo.r ||s |r |e op |e core o |e Copy \eb .|rdo. | |e enoe
\eb s|e yoJ .ar appeas |r ||s ||s. se|ec | ard \|sJa| \eb Deve|ope .||| d|sp|ay |a s|e |r |e
|enoe \eb S|e po|or o |e .|rdo. Crce ||s occJs. s||p o |e re. sec|or |r ||s c|ape
(
C||c| |e 7cbbYWh bJor rea |e op cere o |e Copy \eb .|rdo. T||s d|sp|ays |e Cper \eb
S|e d|a|og bo. s|o.r pev|oJs|y |r ||gJes 4. 4`. ard 44
)
|se |e Cper \eb S|e d|a|og bo. |Js as C|ape 4 |rsJced |eep |r n|rd. |o.eve. |a yoJ'e
oper|rg |e enoe \eb s|e o a Copy \eb opea|or T|e soJce \eb s|e yoJ opered |r sep 1
.||| s||| appea or |e |e
1he Source Web SiLe and RemoLe Web SiLe porLions o Lhe Copy Web dialog box each
display Lhe conLenLs o one older rom Lheir respecLive siLes.
N 1o view Lhe conLenLs o a subolder, double-click iL.
N 1o view Lhe conLenLs o a parenL older, click Lhe NavigaLe Up One DirecLory Level buLLon
jusL above Lhe Lop righL corner o Lhe lisLing.
l you righL-click eiLher older lisLing, a shorLcuL menu will oer Lhe ollowing commands.
N kefresh Reloads Lhe ile and older lisLing. Use Lhis command i you suspecL updaLes
rom anoLher source have superseded Lhe inormaLion on display. 1he Reresh buLLons
jusL above Lhe Lop righL corner o each older lisLing perorm Lhe same uncLion.
N SeIect AII SelecLs all Lhe iles and olders in Lhe older lisLing you righL-clicked.
N Copy SeIected liIes Copies all currenLly-selecLed iles and olders rom Lhe lisLing you
righL-clicked Lo Lhe oLher locaLion.
SeIecting and Copying liIes
To seIect muItipIe fiIes in either
the source or remote web site,
use Shift+cIick or CtrI+cIick just as
you wouId in Microsoft windows


xpIorer. SeIecting a foIder seIects
aII its fiIes and subfoIders.
G < C
C05622124.indd 47 9/9/05 9:41:46 AM
48 Microsoft VisuaI web DeveIoper 2005 xpress dition. BuiId a web Site Now!
N Synchronize SeIected liIes Copies selecLed iles rom eiLher siLe LhaL are absenL or older
on Lhe oLher siLe. AL compleLion, Lhe same iles and olders-wiLh all Lhe newesL Lime
sLamps-will exisL on boLh siLes.
N Copy Site To kemote {or Source) Copies Lhe enLire source Web siLe Lo Lhe remoLe Web
siLe, or vice versa. 1he single-arrow buLLons beLween Lhe Lwo older lisLings also perorm
Lhese uncLions.
N Synchronize Site Works like Synchronize SelecLed Files, excepL LhaL iL perLains Lo Lhe
enLire Web siLe. 1he double-arrow buLLon beLween Lhe Lwo older lisLings also perorms
Lhis uncLion.
N DeIete DeleLes Lhe selecLed iles. 1he DeleLe buLLons jusL above Lhe Lop righL corner o
each older lisLing perorm Lhe same uncLion.
1he square buLLon beLween Lhe Lwo older lisLings provides a Cancel uncLion. l a copy
operaLion seems Lo be running Loo slowly, or i iL mighL be hung, click Lhis buLLon Lo Lermi-
naLe Lhe process.
Keep in mind LhaL when copying iles beLween Lwo exisLing siLes, some iles dj\]i Lo be
dierenL. For example.
N When you copy a working copy o your siLe Lo Lhe live producLion version, you probably
Ydci wanL Lo overwriLe your producLion daLabases. FrequenLly, Lhese reside in your siLe's
6eeT9ViV older.
N 1he lZW#Xdc[^\ ile conLains a myriad o seLLings LhaL aecL your siLe. Many o Lhese
seLLings mighL be Lhe same or developmenL and LesLing, buL many may be dierenL as
well. For example, Lhis is where visual Web Developer sLores Lhe name, locaLion, userid,
and password or accessing your daLabase. 1hese seLLings are usually dierenL or LesLing
Lhan Lhey are or producLion.
Think carefuIIy before copying the
6eeT9ViV foIder from one site to
another. 9dci overwrite your pro-
duction databases!
< @C BEG4AG
Think carefuIIy before copying
the lZW#Xdc[^\ fiIe from one site
to another. 9dci overwrite the
run-time settings for your produc-
tion site!
< @C BEG4AG
C05622124.indd 48 9/9/05 9:41:47 AM
Chapter 5. Copying Your web Site 49
Finally, keep in mind LhaL visual Web Developer supporLs several dierenL ways o com-
piling any program code your siLe conLains.
N ln some approaches, Lhe Web server compiles Lhe code or each page aL run-Lime, LhaL
is, Lhe irsL Lime a visiLor requesLs LhaL page. ln Lhese siLuaLions, you need Lo copy all your
source code Lo Lhe producLion siLe.
N ln oLher cases, you compile Lhe code beore you copy Lhe siLe. ln Lhis environmenL, you
need Lo copy Lhe compilaLion ouLpuL (a DLL) buL noL Lhe source code.
ChapLer 7 will explain more abouL Lhese opLions.
ln Summary.
visual Web Developer provides a Copy Web command LhaL can copy all or parL o one
Web siLe Lo anoLher. 1his is very useul or creaLing a new working copy o your producLion
siLe, and or copying compleLed changes rom Lhe working copy Lo Lhe producLion siLe.
1he nexL chapLer will explain how Lo creaLe and modiy Lhe Web pages in your siLe.
lor more information about com-
piIing program code and deciding
which fiIes need to be on your Iive
production site, refer to, "Storing,
CompiIing, and PubIishing
Program Code, in Chapter 7.
@BE8 < A9 B
C05622124.indd 49 9/9/05 9:41:47 AM
C05622124.indd 50 9/9/05 9:41:47 AM
5l
+
Jbe^\aZj\g[JXU
CTZXI\Xjf(&
4WW\aZ6bageb_f('
FXgg\aZ6bageb_
CebcXeg\Xf(+
4WW\aZbe@bW\Yl\aZ
;lcXe_\a^f)(
|o|e 6
6eXTg\aZTaW
@bW\Yl\aZ
JXUCTZXf
Once you have a Web siLe, or aL leasL a working copy o one, you'll cerLainly
wanL Lo creaLe and modiy Lhe Web pages iL conLains. CreaLing pages is ar
more work-yeL ar more inLeresLing-Lhan creaLing a blank siLe. 1his chapLer
explains how Lo creaLe pages in MicrosoL

visual Web Developer", how Lo


open exisLing pages, and how Lo add and modiy page conLenL.
ln reading Lhis maLerial, keep in mind LhaL a Xdcigda means any
ordinary H1ML Lag or ASP.NF1 server conLrol. ln Lhis sense, Lags like <br>,
<img src="logo.gi">, <orm runaL="server">, complex server conLrols, and
even Lhe Web page iLsel are all conLrols.
C06622124.indd 51 9/9/05 9:44:19 AM
52 Microsoft VisuaI web DeveIoper 2005 xpress dition. BuiId a web Site Now!
TO CkAT Ok OPN A wB PAG
lL's easy Lo creaLe a new Web page in visual Web Developer. Simply ollow Lhis procedure.
Cper |e s|e |a .||| cora|r |e page
% C|oose Ne. |||e on |e |||e nerJ T||s d|sp|ays |e /dd Ne. |en page s|o.r |r ||gJe b1
Here's how Lo compleLe Lhe enLries on Lhe Add
New lLem page.
N TempIate l your page will use any ASP.NF1
eaLures, selecL Web Form. 1his is almosL
always Lhe correcL choice.
l you choose H1ML Page, visual Web
Developer will assign an .hLm ilename
exLension. 1his, in Lurn, bypasses all ASP.NF1
processing when Lhe Web server delivers Lhe
page Lo visiLors.
For a brie descripLion o Lhe oLher LemplaLes,
Lemporarily selecL each one and read Lhe
descripLion LhaL appears in Lhe unLiLled gray
box below Lhe selecLion area. LaLer chapLers
will explain whaL Lo do wiLh many o Lhese
LemplaLes.
N Name Speciy a ilename or Lhe new page. For Web Forms, Lhe deaulL and required
exLension is .aspx.
N Language Speciy Lhe programming language you wanL Lo use or ASP.NF1 program
code (LhaL is, or program code LhaL runs on Lhe Web server). ln visual Web Developer
Fxpress, Lhe choices are MicrosoL visual 8asic

, C#, and J#.


N PIace Code ln Separate liIe SelecL Lhis box i you wanL Lhe Web page's H1ML code and
iLs ASP.NF1 program code Lo reside in separaLe iles. Clear iL Lo keep boLh kinds o code
in Lhe same ile.
;^\jgZ+"&
|e /c: .eo|e o ew |||e |c /c:
||e. ||| J|o|co |cx cm| |c ||e
|/e c| |||e /c: wo|
lor more information about orga-
nizing ASP.NT program code,
refer to the section titIed, "Storing,
CompiIing, and PubIishing
Program Code, in Chapter 7.
@BE8 < A9 B
$
C06622124.indd 52 9/9/05 9:44:20 AM
Chapter 6. Creating and Modifying web Pages 53
N SeIect Master Page SelecL Lhis box i you wanL Lhe new page Lo inheriL Lhe appearance
o a special LemplaLe you've creaLed or your siLe. ALer you click Lhe Add buLLon, visual
Web Developer will Lhen display a SelecL A MasLer Page dialog box where you speciy
Lhe masLer page you wanL.
1here are many ways o opening an exisLing page in visual Web Developer. Here are
Lhree o Lhe mosL common.
N Double-click a ile name in Lhe SoluLion Fxplorer window.
N Choose Open File rom Lhe File menu. 1his displays a sLandard File Open dialog box
where you can choose Lhe ile you wanL.
N Choose RecenL Files rom Lhe File menu and Lhen selecL a ile rom Lhe resulLing submenu.
lor more information about
ASP.NT Master Pages, refer to
Chapter 9, "Using Master Pages to
CentraIize Page Layout.
@BE8 < A9 B
working with web Page Views
For each Web page you open, visual Web Developer provides a choice o Lwo disLincL ediL-
ing modes. 1hese are.
N Design View Provides an ediLable, visual preview o Lhe Web page. However, keep Lhese
excepLions in mind.
N Design view doesn'L acLually run any program code or server conLrols your page
mighL conLain. lnsLead iL displays simulaLed resulLs, blank orm ields, and oLher
placeholders.
N Design view may display conLrols LhaL run on Lhe Web server buL display noLhing in
Lhe browser. 1ypically, such conLrols provide background uncLions such as connecL-
ing Lo daLabases. 1his is so you know Lhe conLrols exisL and so you can selecL Lhem
or ediLing.
N Design view doesn'L reacL Lo mouse clicks, key presses, and oLher evenLs as a browser
would. lnsLead, Lhese evenLs (and oLhers) invoke eaLures LhaL are parL o visual Web
Developer. Clicking a hyperlink, or example, doesn'L display Lhe LargeL page in
Design view. lnsLead, iL selecLs Lhe hyperlink or ediLing.
C06622124.indd 53 9/9/05 9:44:21 AM
Adding ControIs
54 Microsoft VisuaI web DeveIoper 2005 xpress dition. BuiId a web Site Now!
N Source View Displays Lhe source code or your page. ln addiLion Lo H1ML code, Lhis
includes Lypes such as.
N CSS (Cascading SLyle SheeL) code unique Lo your page.
N XML Lags LhaL load ASP.NF1 server conLrols.
N JavaScripL code LhaL runs on Lhe browser.
N visual 8asic, C#, or J# code LhaL runs on Lhe Web server.
1o swiLch beLween Design view and Source view, click Lhe Design or Source Lab aL Lhe
boLLom o Lhe ediLing window.
1he remainder o Lhis chapLer deals exclusively wiLh Design view ediLing. 1he nexL chap-
Ler, "Working wiLh Source Code," will explain Source view ediLing.
Once you have a blank page, your nexL Lask will be adding LexL, picLures, orm ields, or
oLher conLrols Lhe page requires. 1his secLion explains, in a general way, how Lo perorm
Lhese Lasks.
Adding ControIs from the TooIbox
When your page needs Lo use one o Lhe server conLrols LhaL comes wiLh visual Web
Developer, you should immediaLely Lhink o using Lhe 1oolbox window. 1his window is also
useul or adding sLandard H1ML conLrols Lo your page. lL appears along Lhe leL edge o
Figure 6-2.
C06622124.indd 54 9/9/05 9:44:21 AM
Chapter 6. Creating and Modifying web Pages 55
visual Web Developer organizes 1oolbox conLrols inLo uncLional groups, Lhen iL displays
or hides each group depending on Lhe Lype o ile you're ediLing. 1able 6-, or example,
lisLs Lhe Loolbox groups LhaL appear or an ASP.NF1 (.aspx) Web page. For ordinary (.hLm)
Web pages, only Lhe H1ML and Ceneral groups appear.
;^\jgZ+"'
|e cc||cx o| ||e |e|| c| ||| J||o/ .c|o|
o |.| oc|me| c| .c|c| /c: .o oJJ |c
/c: e| ooe c ee ||e |J|v|J:o| .c|c|
| o oc:. .||.| ||o| oc: |: |o (
C06622124.indd 55 9/9/05 9:44:22 AM
56 Microsoft VisuaI web DeveIoper 2005 xpress dition. BuiId a web Site Now!
visual Web Developer provides Lhree dierenL ways o adding 1oolbox iLems Lo a page.
1hey all produce Lhe same resulLs. JusL choose Lhe one you like Lhe besL.
N SeL Lhe inserLion poinL where you wanL Lhe conLrol Lo appear, Lhen double-click iLs
1oolbox enLry.
N Drag Lhe conLrol you wanL rom Lhe 1oolbox window and drop iL on an open Web page.
N ln Lhe 1oolbox window, copy Lhe conLrol you wanL Lo Lhe clipboard, Lhen seL Lhe inserLion
poinL and pasLe Lhe conLrol onLo your Web page.
Group Description
HiVcYVgY Ceneral-purpose Web server conLrols. Many o Lhese are similar Lo H1ML
conLrols, buL are more uncLional.
9ViV Server conLrols designed or accessing, displaying, and updaLing daLabase
inormaLion.
KVa^YVi^dc Server conLrols LhaL veriy Lhe synLax o daLa LhaL visiLors enLer in orm
ields.
CVk^\Vi^dc Server conLrols LhaL display breadcrumbs and drop-down, ly-ouL, and
Lree view menus.
Ad\^c Server conLrols or developing sel-regisLraLion and access conLrol
eaLures.
LZWEVgih Server conLrols LhaL LreaL porLions o Lhe Web page as dynamic areas
LhaL auLhorized visiLors can cusLomize Lo suiL Lheir personal preerences.
ChapLer 8, "Displaying and CusLomizing Web ParLs," will explain Lhis
much urLher.
=IBA Ordinary H1ML conLrols. ALer adding an ordinary H1ML conLrol Lo an
ASP.NF1 (.aspx) page, you can converL iL Lo an H1ML server conLrol.
<ZcZgVa lniLially empLy. 1ypically, Lhis conLains addiLional conLrols you purchase or
develop yoursel.
IVWaZ+"&
cc||cx c: |c e| |cm
C06622124.indd 56 9/9/05 9:44:23 AM
Chapter 6. Creating and Modifying web Pages 57
When working wiLh Lhe 1oolbox or wiLh conLrols already on a page, any sLandard CuL,
Copy, or PasLe procedure will do. For example, Lo copy someLhing Lo Lhe clipboard, irsL
selecL iL Lhen press CLl-C, righL-click and choose Copy, or choose Copy rom Lhe FdiL menu.
Adding TabIes and Layers from the Menu Bar
AlLhough you can creaLe an H1ML Lable by using Lhe 1able enLry in Lhe 1oolbox's H1ML
group, Lhis meLhod provides liLLle lexibiliLy. ou geL Lhe same iniLial Lable properLies every
Lime. For more lexibiliLy, Lry Lhe ollowing procedure.
TO ADD TABLS AND LAYkS lkOM TH MNU BAk
Se |e |rse|or po|r .|ee yoJ .ar |e ab|e o appea
C|oose =bgYfhHUV`Y on |e |ayoJ nerJ
|||| oJ |e |rse Tab|e d|a|og bo.. |er c||c| C?
l you wish, you can also add layers Lo your page Lhis way. JusL seL Lhe inserLion poinL
and Lhen choose lnserL Layer rom Lhe LayouL menu. However, visual Web Developer won'L
display an lnserL Layer dialog box. ou geL a generic layer, jusL as i you'd used Lhe Div enLry
in Lhe 1oolbox's H1ML group.
Adding ControIs from SoIution xpIorer
l a ile appears in SoluLion Fxplorer, you can generally add iL Lo an open page by dragging
and dropping. 1haL is, you can drag Lhe ilename rom SoluLion Fxplorer and drop iL onLo an
open Web page. 1he resulLs you geL rom Lhis meLhod depend on Lhe Lype o ile. Here are
some examples.
N l you drag a picLure ile (or example, one wiLh a .gi or .jpg ilename exLension), visual
Web Developer creaLes an <img> Lag LhaL displays LhaL picLure.
N l you drag a Cascading SLyle SheeL (.css) ile, visual Web Developer links LhaL sLylesheeL
Lo your page.
$
%
&
C06622124.indd 57 9/9/05 9:44:23 AM
58 Microsoft VisuaI web DeveIoper 2005 xpress dition. BuiId a web Site Now!
N l you drag a User conLrol (LhaL is, a ile wiLh an .ascx ilename exLension), visual Web
Developer adds.
N A <% @ConLrol . . . %> Lag LhaL poinLs Lo Lhe .ascx ile and assigns iL a Lag name
(unless such a Lag already exisLs).
N An XML Lag wiLh Lhe given Lag name. 1his loads Lhe conLrol in Lhe locaLion where
you drop iL.
N l you drag a Web page (or example, one wiLh an .hLm or .aspx ilename exLension)
visual Web Developer creaLes a link Lo LhaL page. 1he ilename will be Lhe hyperlink LexL.
l dragging a ile rom SoluLion Fxplorer doesn'L produce Lhe resulLs you wanL, simply
press CLrl-Z (undo) and use Lhe 1oolbox Lo creaLe Lhe Lype o conLrol you wanL.
Once you've added an H1ML or server conLrol Lo your page, you'll almosL cerLainly wanL
Lo modiy one or more o iLs properLies. 1his secLion describes Lhe varieLy o ways you can
modiy such properLies wiLhouL leaving Design view.
Setting Properties with the Properties window
visual Web Developer provides a ProperLies window LhaL displays and ediLs Lhe properLies
o any conLrol you choose. A version o Lhis window appears in Lhe boLLom righL corner o
Figure 6-8.
1he ProperLies window always displays Lhe properLies o Lhe currenLly-selecLed conLrol.
1o selecL a conLrol and display iLs properLies, righL-click iL and choose ProperLies. However,
simply selecLing Lhe conLrol usually has Lhe same eecL.
xpect minor variations in the way
the Properties window works for
various controIs.
G < C
lor more information about ASP.
NT User controIs, refer to Chapter
8, "Creating and Using web User
ControIs.
@BE8 < A9 B
Setting ControI Properties
C06622124.indd 58 9/9/05 9:44:23 AM
Chapter 6. Creating and Modifying web Pages 59
l you have diiculLy selecLing Lhe exacL conLrol you wanL, reer Lo Lhe Ouick 1ag 1oolbar
aL Lhe boLLom o Lhe ediLing window. 1his is Lhe Loolbar LhaL displays <body> <div> in
Figure 6-2 and <body> <p> <asp.dropdownlisL#dropdow . . . > in Figure 6-8.
1he Ouick 1ag 1oolbar always displays a Lag name or Lhe currenL conLrol and all iLs
conLainers, up Lo and including Lhe <body> Lag. For an H1ML Lable cell, or example,
Lhe Ouick 1ag Loolbar displays <body> <Lable> <Lr> <Ld>. (l necessary, use Lhe arrow
buLLons Lo scroll Lhe lisL o Lags leL or righL.) Clicking any o Lhese Lag names selecLs Lhe
corresponding conLrol.
1he DocumenL OuLline window LhaL appears along Lhe leL edge o Figure 6-8 provides
anoLher way o locaLing and selecLing Lhe conLrol you wanL.
;^\jgZ+"(
|e o ce|/ vo|:e |cx .c|o| o
e|||| |:||c. .||.||o ||o| |:||c J||o/ o
J|o|co |cx |c .c||o:|o ||o| ce|/ |e
|c.:me| (:|||e w|Jcw o| ||e |e|| c| |||
J||o/ |||:|o|e ||e |:.|:e c| /c:
e| ooe
||||ps|s |Jor
C06622124.indd 59 9/9/05 9:44:24 AM
60 Microsoft VisuaI web DeveIoper 2005 xpress dition. BuiId a web Site Now!
N 1o display Lhis window, choose DocumenL OuLline rom Lhe view menu.
N 1o selecL a conLrol, selecL iL in Lhe DocumenL OuLline window. 1his selecLs Lhe same
conLrol in Design view and displays iLs properLies in Lhe ProperLies window.
Once you've selecLed Lhe conLrol you wanL Lo modiy, you're ready Lo sLarL using Lhe
ProperLies window. 1he irsL conLrol in Lhe Lhis window is a drop-down lisL LhaL shows Lwo
Lypes o iLems.
N All parenLs o Lhe currenL conLrol.
N All server conLrols in Lhe currenL page.
1o selecL and Lhen modiy Lhe properLies o any o Lhese conLrols, selecL LhaL conLrol rom
Lhe drop-down lisL.
1he second conLrol in Lhe ProperLies window is a Loolbar LhaL displays up Lo ive buLLons.
Some buLLons may be absenL or dimmed, depending on Lhe conLrol. 1hese buLLons are, in
order.
N Categorized Croups Lhe lisL o properLies by caLegory. Figure 6-8 shows Lhis opLion in
eecL or a 9gde9dlcA^hi conLrol. 1his conLrol has six caLegories. AccessibiliLy,
Appearance, 8ehavior, DaLa, LayouL, and Misc. 1he caLegories or oLher conLrols will likely
be dierenL.
N AIphabeticaI LisLs all properLies in alphabeLical order, wiLh no caLegory headings.
N Properties Speciies LhaL you wanL Lhe ProperLies window Lo display Lhe conLrol's prop-
erLies as in Figure 6-8.
N vents Speciies LhaL you wanL Lhe ProperLies window Lo display Lhe conLrol's evenLs.
1he ProperLies window only lisLs evenLs LhaL cause ASP.NF1 Lo run code on Lhe Web
server. lL doesn'L lisL evenLs LhaL code on Lhe browser will handle.
N Property Pages Displays a specialized dialog box, i any, LhaL conigures Lhe conLrol's
properLies. Only a ew conLrols have such dialog boxes.
C06622124.indd 60 9/9/05 9:44:25 AM
Chapter 6. Creating and Modifying web Pages 6l
1o modiy a properLy, click Lhe value box aL Lhe righL o Lhe properLy LiLle. 1hen, proceed
as ollows.
N l Lhe value appears as LexL, Lype iL or ediL iL.
N l a drop-down arrow appears aL Lhe righL o Lhe value box, click iL and selecL a value
rom Lhe resulLing lisL.
N l an ellipsis (. . .) buLLon appears as shown in Figure 6-8, click iL and use Lhe resulLing
dialog box Lo conigure Lhe properLy.
l you wanL Lo wriLe code LhaL runs on Lhe Web server whenever a cerLain evenL occurs,
Lake Lhe ollowing sLeps.
TO wklT SkVk COD THAT kSPONDS TO A wB PAG VNT
Se|ec |e coro| |a a|ses |e ever
\|er |e coro|'s pope|es appea |r |e |ope|es .|rdo.. c||c| |e |vers bJor
&
DoJb|ec||c| |e ever yoJ .ar o ac Jpor (|e ]VcYaZ) \|sJa| \eb Deve|ope .||| s.|c| o SoJce
v|e. ard ceae a dJnny (|e enpy) ever |ard|e /dd |e pogan code yoJ .ar .|||r ||s
ever |ard|e
'
/e yoJ eJr o Des|gr v|e.. |e |ope|es .|rdo. .||| d|sp|ay |e re. ever |ard|e's rane ae
|e ever rane
To na|e |e |ope|es .|rdo. orce aga|r d|sp|ay |e coro|'s pope|es. c||c| |e |ope|es bJor
Setting Properties with the Mouse
ln Design view you can move and resize many Web page conLrols by using sLandard
Windows mouse movemenLs. For example.
N 1o resize a conLrol, selecL iL and Lhen drag one edge or a sizing handle.
$
%
(
C06622124.indd 61 9/9/05 9:44:25 AM
62 Microsoft VisuaI web DeveIoper 2005 xpress dition. BuiId a web Site Now!
N 1o reposiLion a conLrol, irsL selecL iL, Lhen move Lhe mouse over iLs inLerior. When Lhe
mouse poinLer Lakes on Lhis appearance.
drag Lhe conLrol Lo Lhe new locaLion you wanL.
Some conLrols, like Lhe Ad\^cK^Zl conLrol shown below, display a Move decoraLion
whenever iL's possible Lo relocaLe Lhe conLrol by dragging. ln such cases, you can move
Lhe conLrol by dragging Lhe Move decoraLion.
N ou can also move conLrols by cuLLing and pasLing.
N 1o duplicaLe a conLrol, copy and pasLe iL.
Don'L overlook Lhe commands LhaL appear on shorLcuL menus when you righL-click a
conLrol. For Lhe mosL parL Lhese should be very amiliar. CuL, Copy, PasLe, DeleLe, and so
orLh. 1he ollowing commands, however, are worLh special menLion.
N StyIe Displays a SLyle 8uilder dialog box where you can conigure CSS properLies or Lhe
conLrol.
N kun As Server ControI ConverLs an ordinary H1ML conLrol Lo an H1ML server conLrol.
ou need Lo do Lhis i you wanL server-side code Lo manipulaLe Lhe conLrol or iLs
conLenLs.
N dit lmage Loads a picLure inLo Lhe ediLor your compuLer associaLes wiLh Lhe picLure's
ile Lype.
N Show Smart Tag Displays a special iVh`bZcj LhaL displays commands and seLLings
unique Lo a speciic Lype o conLrol. 1he nexL secLion explains smarL Lags and Lask menus.
\ove Decoa|or
C06622124.indd 62 9/9/05 9:44:25 AM
Chapter 6. Creating and Modifying web Pages 63
N Auto lormat Displays an AuLo FormaL dialog box where you can choose Lo apply pre-
made ormaLLing schemes Lo Lhe conLrol.
N dit TempIate Displays a submenu lisLing o all Lhe LemplaLes applicable Lo Lhe given
conLrol. SelecLing a LemplaLe displays a Lask menu wiLh commands or modiying LhaL
LemplaLe. One o Lhese commands is Fnd 1emplaLe FdiLing , which saves changes and
closes Lhe Lask menu.
N kefresh Displays Lhe currenL Web page rom scraLch. 1his correcLs any laws in Lhe cur-
renL display.
N Properties SelecLs Lhe conLrol and displays iLs properLies in Lhe ProperLies window.
However, or a ew conLrols, Lhis command also displays a specialized dialog box or con-
iguring Lhe conLrol.
Setting Properties with Smart Tags
Some Lypes o conLrols have a special decoraLion called a smarL Lag. Clicking Lhis decoraLion
displays a Lask menu unique Lo LhaL conLrol. Figure 6-4 shows Lhe smarL
Lag and Lhe resulLing Lask menu or a <g^YK^Zl conLrol. 1his Lype o
conLrol displays inormaLion rom a 9ViVHdjgXZ (i.e. rom a daLabase).
ln Lhis example, Lhe AuLo FormaL and FdiL 1emplaLe commands work
as Lhe previous secLion described or regular shorLcuL commands. 1he
Choose DaLa Source, FdiL Columns, and Add New Column commands
are speciic Lo Lhe <g^YK^Zl conLrol.
l you can'L ind Lhe specialized properLy seLLings or a speciic conLrol, Lry looking or a
smarL Lag and iLs resulLing Lask menu.
Setting Properties with the lormat Menu
visual Web Developer has a FormaL menu LhaL auLomaLes many common ormaLLing Lasks.
For Lhe mosL parL, Lhe commands on Lhis menu work like Lhose on Lhe FormaL menu o any
oLher MicrosoL Windows

program.
;^\jgZ+")
'cme .c|c| |ove mo| |oo ||o|
J||o/ e.|o||zeJ |o| me: |c ||o|
.c|c|
Sna Tag
C06622124.indd 63 9/9/05 9:44:26 AM
64 Microsoft VisuaI web DeveIoper 2005 xpress dition. BuiId a web Site Now!
visual Web Developer also has a LayouL
menu LhaL provides commands or adding
and modiying H1ML Lables, or adding Layers
(<div> Lags), and or speciying CSS posiLioning
properLies or any conLrol. 1he LayouL menu
appears in Figure 6-5.
For Lhe mosL parL, Lhese commands work
very much as you'd expecL. 1he lnserL 1able and
lnserL, DeleLe, SelecL, Resize, and Merge Cells
commands only apply Lo H1ML Lables.
1he PosiLion command seLs Lhe currenL
conLrol's CSS posiLioning mode Lo AbsoluLe,
RelaLive, SLaLic, or NoL SeL. 1hese are sLandard CSS properLies.
Setting Properties with TooIbars
visual Web Developer includes Lwo Loolbars LhaL modiy Lhe appearance and posiLion o
conLrols. 1hese are.
N The lormatting TooIbar is similar Lo Lhose you ind in MicrosoL Oice applicaLions. FirsL
you selecL Lhe LexL or conLrol you wanL Lo modiy, Lhen you click Lhe drop-down lisL or
buLLon or Lhe properLy you wanL Lo seL. Many commands on Lhe FormaLLing Loolbar
duplicaLe Lhose on Lhe FormaL menu.
N The Layout TooIbar applies only Lo conLrols LhaL use VWhdajiZedh^i^dc^c\. 1his is a CSS
Lechnique LhaL orces conLrols Lo appear aL speciic x-y coordinaLes on Lhe Web page.
l you wanL Lo use absoluLe posiLioning or every conLrol on your page, ollow Lhis
procedure.
;^\jgZ+"*
|e |o/c:| me: cv|Je o :e|:| oc|me| c|
.cmmoJ |c wc||o w||| ||| |o||e oJ |o/e
To set a controI's ide!aZ[i!]Z^\]i!
and l^Yi] properties, choose StyIe
from the lormat menu and then
cIick Position.
G < C
C06622124.indd 64 9/9/05 9:44:27 AM
Chapter 6. Creating and Modifying web Pages 65
TO US ABSOLUT POSlTlONlNG lOk VkY CONTkOL ON A PAG
C|oose Dcg]h]cb on |e |ayoJ nerJ. ard |er c|oose 5ihc!Dcg]h]cbCdh]cbg
%
\|er |e Cp|ors d|a|og bo. s|o.r |r ||gJe bb
appeas. na|e sJe |e |T\| Des|gre ee rode |s
oper ard CSS |os||or|rg |s se|eced
To Jse abso|Je pos||or|rg o ary coro|s yoJ sJbse
oJer|y add o a page
Q Se|ec |e c|ec| bo. ||ed C|arge |os||or|rg To T|e
|o||o.|rg |o Coro|s /dded |s|rg T|e Too|bo.. |ase. C
Dag /rd Dop
Q C|oose /bso|Je|y |os||ored on |e dopdo.r ||s
'
| yoJ .ar \|sJa| \eb Deve|ope o 'srap' abso|Je
pos||or|rg neasJeners o e.ac nJ||p|es o
a p|.e|
Q Se|ec |e c|ec| bo. ||ed Srap ||.e|based |os||ors /rd S|.es To T|e |o||o.|rg Se|rg
Q |se |e |o|.ora| Spac|rg ard \e|ca| Spac|rg e. bo.es o a spec|y |e g|d s|.e yoJ .ar
Adding or Modifying HyperIinks
visual Web Developer can converL any picLure or LexL on your page Lo a hyperlink. Here's
Lhe procedure.
$
&
;^\jgZ+"+
|ee e|||o | ||e (||c J|o|co
|cx .c|c| ||e :e c| o|c|:|e c|
||c|o |c .c|c| /c: :|eo:e||/
oJJ |c o ooe
C06622124.indd 65 9/9/05 9:44:27 AM
66 Microsoft VisuaI web DeveIoper 2005 xpress dition. BuiId a web Site Now!
TO ADD Ok MODllY A HYPkLlNK
Se|ec |e e. o p|cJe yoJ .ar o be a |ype||r|
Ta|e ary dcZ o |ese ac|ors
Q C|oose Corve To |ype||r| on |e |ona nerJ
Q C||c| |e Corve To |ype||r| bJor or |e |ona|rg oo|ba
Q |ess C||
\|er |e |ype||r| d|a|og bo. appeas. se|ec |e pooco| (sJc| as ]iie/) ard |er e||e
Q C||c| |e |o.se bJor o se|ec a |ype||r| des|ra|or on |e cJer \eb s|e
Q |ey |r |e |||
C||c| |e C? bJor
1o speciy addiLional hyperlink properLies, selecL Lhe hyperlink and use Lhe ProperLies
window, jusL as you would or any oLher conLrol.
ln Summary.
ln visual Web Developer, adding conLrols Lo a Web page is easy. Depending on Lhe Lype o
conLrol, you can drag iL rom Lhe 1oolbox, drag iL rom SoluLion Fxplorer, or inserL iL using
a menu.
Once Lhe conLrol is parL o your page, you can modiy iL by selecLing iL and using Lhe
ProperLies window, by dragging or sLreLching iL wiLh Lhe mouse, by righL-clicking iL and
using a shorLcuL menu, by clicking iLs smarL Lag and using a Lask menu, by using main menu
commands, by using Lhe ormaLLing or posiLioning Loolbar.
ChapLer 7 will explain Lhe various ways LhaL visual Web Developer can work wiLh
source code.
$
%
&
'
C06622124.indd 66 9/9/05 9:44:28 AM
67
Hf\aZg[XGXkg8W\gbe)+
Fgbe\aZ6b`c\_\aZ
TaWChU_\f[\aZCebZeT`
6bWX+%
|o|e
Jbe^\aZj\g[
FbheVX6bWX
l you've never used an advanced programming ediLor Lo creaLe Web
pages, you're in or boLh a shock and a LreaL because MicrosoL

visual
Web Developer" comes wiLh Lhe same source code ediLor as high-end
versions o MicrosoL visual SLudio

.
Source code, in Lhis sense, doesn'L necessarily mean ASP.NF1 program
code. ln visual Web Developer, source code includes H1ML, CSS, XML,
JavaScripL LhaL runs on Lhe browser, and so orLh. 1his means you're almosL
cerLain Lo encounLer Lhe source code ediLor, and more likely sooner Lhan
laLer.
ForLunaLely, despiLe iLs power, Lhe visual
SLudio LexL ediLor is very easy Lo use. Once
you undersLand iLs key eaLures, you'll quickly
sLarL creaLing more code wiLh ewer keysLrokes and ewer errors Lhan ever
beore. 1o help you, Lhis chapLer begins wiLh an inLroducLion Lo Lhe visual
SLudio (and Lhereore Lhe visual Web Developer) LexL ediLor.
1he chapLer's inal secLion explains your opLions or sLoring any ASP.
NF1 program code you do wriLe and or compiling a siLe beore or aLer
you copy iL Lo anoLher server. However, neiLher Lhis chapLer nor Lhis book
provide an inLroducLion Lo programming. l LhaL's whaL you need, consider a
more deLailed book such as B^Xgdhd[i6HE#C:I'#%Egd\gVbb^c\HiZe7nHiZe
rom MicrosoL Press

.
,
OccasionaIIy, even the most
dedicated advocates of wYSlwYG
editing work directIy with code.
ABG 8
C07622124.indd 67 9/9/05 9:46:51 AM
68 Microsoft VisuaI web DeveIoper 2005 xpress dition. BuiId a web Site Now!
Using the Text ditor
visual Web Developer can open any ile in your siLe in LexL mode (provided, o course, LhaL
Lhe ile is LexLual).
TO OPN A llL lN TXT MOD
lf VisuaI web DeveIoper supports
onIy one editing mode for a given
type of fiIe, it doesn't dispIay edit-
ing mode tabs at the bottom of
the editing window.
ABG 8
;^\jgZ,"&
|e V|:o| e| |eve|ce |ex| eJ||c o|c:J
w||| cwe|:| |eo|:e |c |o|e. c|e ||e .c|c
.cJ|o. ||e ||e :m|e|o. oJ ||e .c||o|||e
|o.|e|
$
Cper o ceae |e ||e as C|ape
b d|eced
%
| |e SoJce ab a |e boon o
|e ed||rg .|rdo. |s peser bJ
ro se|eced. se|ec |
Figure 7- shows how visual
Web Developer displays an ASP.
NF1 Web page in Source view.
Fven Lhough Source view is in
eecL, Lhe 1oolbox, Lhe Ouick 1ag
1oolbar, and Lhe ProperLies window
are enabled and working. For
example, you can.
N Add conLrols by dragging Lhem
rom Lhe 1oolbar and dropping
Lhem onLo your source code.
N SelecL Lags by clicking Lheir
icons in Lhe Ouick 1ag 1oolbar.
N view and modiy conLrol
properLies by using Lhe
ProperLies window.
C07622124.indd 68 9/9/05 9:46:53 AM
Chapter 7. working with Source Code 69
1he ediLor auLomaLically displays line numbers and also displays dierenL Lypes o code
in dierenL colors. ln Lhe igure, or example, H1ML Lag names are dark red, aLLribuLe names
are brighL red, aLLribuLe values are blue, and ordinary LexL is black. Similar convenLions apply
Lo CSS, program, and oLher kinds o code.
Using OutIining
For many kinds o source code, visual Web Developer can collapse and expand blocks o
code. 1his reduces cluLLer and scrolling and makes iL easier Lo work wiLh only Lhe code LhaL
concerns you aL Lhe momenL. Figure 7-2 shows ouLlining in acLion.
To configure the way the text
editor dispIays your code, choose
Options from the TooIs menu.
Then, when the Options diaIog box
appears, open the Text ditor node
in the tree view box at the Ieft.
@BE8 < A9 B
;^\jgZ,"'
c||oeJ ||c.| c| .cJe |eo| o| ||e
'. 14. oJ || o..c:| |c ||e
|eo| | ||e :m|e|o oJ |c ||e
|: |o ( |xoJ |.c
C07622124.indd 69 9/9/05 9:46:54 AM
70 Microsoft VisuaI web DeveIoper 2005 xpress dition. BuiId a web Site Now!
ln Lhis igure.
N Lines 5- conLain a <scripL> . . . </scripL> block, buL Lhe developer previously clicked
Lhe Collapse icon, a minus sign (-), LhaL appears on line 5 o Figure 7-. 1his Lells Lhe edi-
Lor noL Lo display Lhe conLenLs o Lhe block.
l Lhe developer wanLs Lo view or modiy Lhe block, he or she would simply click Lhe
Fxpand icon (-) LhaL now appears on line 5.
N Lines 4-9 conLain Lhe <head> . . . </head> secLion o Lhe Web page. 1he developer
has collapsed Lhis as well.
N Lines 22-47 conLain Lhe code or an H1ML Lable, buL Lhe developer collapsed Lhis block,
Loo.
N 1he developer could also collapse.
N 1he <asp.DropDownLisL> . . . <asp.DropDownLisL> block on lines 58-58.
N 1he <p> . . . </p> block on lines 52-59.
N 1he <orm> . . . </orm> block on lines 2-60.
N 1he <body> . . . </body> block on lines 20-6.
N 1he <hLml> . . . </hLml> block on lines 8-62.
ln each case, Lhe developer would click Lhe minus icon (-) LhaL appears jusL Lo Lhe righL
o Lhe sLarLing line number.
l you run a Find or Replace command on a ile LhaL conLains collapsed blocks, you can
choose wheLher or noL Lo search Lhe hidden LexL. l you do search hidden LexL and ind a
maLch, Lhe ediLor will expand any collapsed blocks LhaL conLain iL.
C07622124.indd 70 9/9/05 9:46:54 AM
Chapter 7. working with Source Code 7l
Using SpIit View
Like MicrosoL Oice programs, visual Web Developer can spliL Lhe ediLing window inLo Lwo
panes LhaL you can scroll independenLly. 1his makes iL easy Lo work on Lwo blocks o code aL
once or Lo view one block while working on anoLher. 1o use Lhis eaLure, eiLher.
N Use Lhe mouse Lo grab Lhe spliL handle LhaL appears jusL above Lhe ediLing window's
verLical scroll bar and drag iL Lo Lhe locaLion you wanL. (1he spliL handle looks like a Liny
unlabeled buLLon or "bump.")
N SelecL some LexL or seL Lhe inserLion poinL inside Lhe ediLing window. 1hen, choose SpliL
rom Lhe Window menu.
1o reLurn Lo single pane view, eiLher.
N Drag Lhe spliL bar back Lo iLs
original posiLion aL Lhe Lop o
Lhe window.
N Choose Remove SpliL rom Lhe
Window menu.
Figure 7-8 shows SpliL view
in eecL.
;^\jgZ,"(
| '||| mcJe. ||e eJ||c J||o/ |wc J|||ee|
e.||c c| ||e ome |||e
C07622124.indd 71 9/9/05 9:46:56 AM
72 Microsoft VisuaI web DeveIoper 2005 xpress dition. BuiId a web Site Now!
Using Go To, Bookmarks, and the Task List
1he LexL ediLor can posiLion iLs display aL any line number you wanL. 1o use Lhis eaLure, irsL
choose Co 1o rom Lhe FdiL menu or press CLrl-C. 1hen, Lype Lhe line number you wanL and
click OK.
8ookmarks provide anoLher way o moving rapidly Lo Lhe code you wanL. 1o use Lhis
eaLure, you seL a bookmark aL Lhe beginning o each block o code you're ediLing, and
Lhen use shorLcuL keys, Loolbar buLLons, or menu commands Lo jump orward or backward
Lhrough Lhe bookmarks. 1he 1exL FdiLor Loolbar and Lhe FdiL menu (under 8ookmarks)
provide a varieLy o commands or seLLing, posiLioning Lo, and clearing bookmarks.
1he Lask lisL sLores reminders o work you need Lo do. 1o add such a reminder or a
speciic line o code, selecL Lhe line o code, Lhen choose 8ookmarks rom Lhe FdiL menu and
click Add 1ask LisL ShorLcuL. 1o come back Lo LhaL line o code use Lhe ollowing procedure.
TO US A TASK LlST SHOkTCUT
$

C|oose HUg_@]gh on |e \|e. nerJ
%

\|er |e Tas| ||s .|rdo. appeas. c|oose G\cfhWihg |r |e dopdo.r ||s rea |e op
&

T|e |o.e pa o |e .|rdo. .||| d|sp|ay a ||s o s|ocJs yoJ've saved
Q To pos||or |e ed|o a |e ||re o ary as|. doJb|ec||c| |a as|
Q To na| a as| as conp|ee. se|ec |e c|ec| bo. |r |e secord co|Jnr
Q To de|ee a as|. se|ec | ard pess |e De|ee |ey
VisuaI web DeveIoper bookmarks
have no direct reIation to HTML
bookmarks that you define with
<a name=Wdd`bVg`> tags.
G < C
VisuaI web DeveIoper remembers
bookmarks and task Iist shortcuts
from one editing session to the
next.
ABG 8
C07622124.indd 72 9/9/05 9:46:56 AM
Chapter 7. working with Source Code 73
Figure 7-4 shows visual Web Developer displaying a page wiLh Lwo bookmarks and one
Lask lisL shorLcuL.
Making Sense of lnteIIiSense
Wouldn'L iL be greaL i your LexL ediLor keyed in mosL o your Lag names, aLLribuLe names,
aLLribuLe values, aposLrophes, and closing Lags or you And i, along Lhe way, iL consLanLly
coached you wiLh lisLs o possible choices Well, LhaL's whaL Lhe lnLelliSense eaLure does.
The terms XdYZXdbeaZi^dc and
hiViZbZciXdbeaZi^dc aIso refer
to lnteIIiSense. However, the
word >ciZaa^HZchZ is a Microsoft
trademark.
ABG 8
;^\jgZ,")
|e ||:e |oJ|o c ||e 1 oJ ' |J|.o|e
|cc|mo| |e o| ||| w|Jcw J||o/ o
ce |o| |c ||e 1'
C07622124.indd 73 9/9/05 9:46:57 AM
74 Microsoft VisuaI web DeveIoper 2005 xpress dition. BuiId a web Site Now!
Suppose, or example, you're enLering H1ML code. When you Lype Lhe opening angle
brackeL (<) or a Lag, lnLelliSense displays a selecLion lisL o valid Lag names as shown in
Figure 7-5.
;^\jgZ,"*
|e wc||o w||| |||. |/|o o
|oo ce|o oo|e |o.|e| .o:e
||e|||'ee |c J||o/ o e|e.||c |||
c| vo||J |oo ome
l you conLinue Lo Lype, lnLelliSense posiLions Lhe selecLion lisL aL Lhe irsL maLching enLry.
ln Lhe igure, or example.
N 1he developer has Lyped p. 1hereore, lnLelliSense has posiLioned Lhe lisL Lo Lhe irsL
enLry beginning wiLh e.
N l Lhe developer Lhen Lyped r, lnLelliSense would posiLion Lo Lhe irsL enLry beginning
wiLh eg, and so orLh.
C07622124.indd 74 9/9/05 9:46:58 AM
Chapter 7. working with Source Code 75
ou can also selecL an iLem rom Lhe lnLelliSense lisL by using Lhe mouse Lo scroll
Lhrough Lhe lisL and Lhen clicking Lhe enLry you wanL.
Once you've Lyped or selecLed Lhe Lag name you wanL, add iL Lo Lhe page by Laking dcZ
o Lhese Lhree acLions.
N Double-click Lhe correcL Lag name in Lhe selecLion lisL.
N Press Lhe 1ab key.
N 1ype any characLer LhaL, according Lo Lhe rules o H1ML, marks Lhe end o Lhe Lag name.
For example, Lype a space or a closing angle brackeL (>).
1he lead-in or an H1ML aLLribuLe is a space. l you Lype a space immediaLely aLer any
Lag name or aLLribuLe, a selecLion lisL o permissible aLLribuLe names will appear as shown in
Lhe middle o Figure 7-5.
1o selecL an aLLribuLe name, repeaL Lhe procedure you used or Lhe Lag name. 1hen, Lype
Lhe equal sign (=) LhaL leads inLo Lhe aLLribuLe value. l Lhe given aLLribuLe has a limiLed seL
o correcL values, lnLelliSense will display Lhem in yeL anoLher selecLion lisL like Lhe righLmosL
example in Figure 7-5.
When you Lype Lhe Lag's closing angle brackeL (>), lnLelliSense will auLomaLically provide
a closing Lag. For example, when you Lype Lhe closing angle brackeL (>) aL Lhe end o <p
align=leL>, lnLelliSense will auLomaLically supply an </p> Lag and seL Lhe inserLion poinL
beLween Lhe opening and closing Lags.
NoLe LhaL lnLelliSense lisLs appear because you Lype a lead-in (or Lrigger) characLer, such
as an opening angle brackeL (<) in H1ML. l or some reason Lhe selecLion lisL disappears,
seLLing Lhe cursor immediaLely aLer Lhe lead-in characLer won'L bring Lhe drop-down lisL
back. lnsLead you musL eiLher.
N DeleLe and re-enLer Lhe lead-in characLer (in Lhis case, Lhe opening angle brackeL).
N Choose lnLelliSense rom Lhe FdiL menu, and Lhen choose LisL Members.
N Press CLrl-J.
To configure lnteIIiSense process-
ing, choose Options from the TooIs
menu. when the Options diaIog
box appears, open the Text ditor
node, seIect a fiIe type, and choose
the options you want under the
Statement CompIetion heading at
the right.
G < C
Using lnteIIiSense is aIways option-
aI. lf you ignore the lnteIIiSense
Iist and key in an HTML tag {or
anything eIse) compIeteIy by hand,
lnteIIiSense won't interfere with
the characters you enter.
G < C
C07622124.indd 75 9/9/05 9:46:58 AM
76 Microsoft VisuaI web DeveIoper 2005 xpress dition. BuiId a web Site Now!
visual Web Developer supporLs lnLelliSense noL only or H1ML, buL also or XML,
JavaScripL, CSS, and all .NF1 programming languages.
Detecting Syntax rrors
As you enLer your code, visual Web Developer consLanLly checks or synLax errors. 1hen, or
each error, iL.
At first, lnteIIiSense might seem
more Iike an lnternet pop-up
generator than a productivity
tooI. NevertheIess, after just a
IittIe practice, most deveIopers
find they can't Iive without it.
lnteIIiSense saves typing, improves
accuracy, and saves hours of Iook-
ing up vaIues and speIIings.
G < C
;^\jgZ,"+
V|:o| e| |eve|ce Je|e.|
oJ ||o|||o|| /|ox ec |
/c: c:.e .cJe
N Displays a red squiggly line
under Lhe bad code.
N Displays Lhe error message,
line number, and ilename in
an Frror LisL window. l you
double-click Lhis message, Lhe
ediLor displays Lhe problem
line.
N Displays Lhe error message
as a LoolLip i you hover Lhe
mouse over Lhe bad code.
Figure 7-6 shows how Lhis
looks in pracLice.
.1o choose Lhe browser version
or H1ML speciicaLion (LhaL is, Lhe
hX]ZbV) you wanL Lo use or cre-
aLing and validaLing Web pages,
ollow Lhe nexL procedure.
VisuaI web DeveIoper wiII frequentIy report syntax errors whiIe you're in
the middIe of typing an HTML tag or program statement. This is no cause for
concern. The error message wiII disappear when you finish typing the tag or
statement.
G < C
C07622124.indd 76 9/9/05 9:47:00 AM
Chapter 7. working with Source Code 77
TO CHOOS AN HTML SCHMA
$

C|oose Cp|ors on |e Too|s nerJ
%
\|er |e Cp|ors d|a|og bo. appeas. oper Te. |d|o. |T\|. ard \a||da|or |r |e ee v|e. bo. a
|e |e
&

Se|ec |e bo.se o |T\| spec||ca|or yoJ .ar on |e Tage dopdo.r ||s a |e |g|
ou can also choose a browser version or H1ML speciicaLion by using Lhe drop-down lisL
on Lhe H1ML Source FdiLing Loolbar.
linding and kepIacing Text
visual Web Developer provides exLremely powerul commands or inding and searching LexL.
TO US llND AND kPLAC COMMANDS
$

C|oose ||rd /rd |ep|ace on |e |d| nerJ
%
C|oose ore o |e ava||ab|e sJbconnards T||s .||| d|sp|ay a ||rd /rd |ep|ace d|a|og bo. |||e |ose
s|o.r |r ||gJe
&
\|sJa| \eb Deve|ope oes |ve ||rd /rd |ep|ace connards | yoJ d|scove |a yoJ've c|oser |e
.org connard. Jse |e dopdo.r ||ss a |e op o |e d|a|og bo. o se|ec |e ore yoJ .ar
To dispIay the HTML Source
diting tooIbar, choose TooIbars
from the View menu, and then
choose HTML Source diting.
G < C
C07622124.indd 77 9/9/05 9:47:00 AM
78 Microsoft VisuaI web DeveIoper 2005 xpress dition. BuiId a web Site Now!
1he ive Find And Replace commands are.
N Ouick lind Searches or all occurrences o a given sLring in Lhe currenL documenL, Lhe
currenL selecLion, all open documenLs, or Lhe currenL projecL. 1wo modes o searching are
available.
N lind Next Advances sequenLially Lo Lhe nexL occurrence o Lhe given LexL each Lime
you click a Find NexL buLLon or (i you've closed Lhe Find And Replace dialog box)
each Lime you press F8.
N Bookmark AII ln one operaLion, seLs a visual Web Developer bookmark on each line
LhaL conLains Lhe given LexL. 1his mode, however, isn'L available when using Ouick
Find Lo search an enLire Web siLe
lor more information about VisuaI
web DeveIoper bookmarks, refer
to the section titIed, "Using Go
To, Bookmarks, and the Task List
earIier in this chapter.
@BE8 < A9 B
;^\jgZ,",
|ee oe |wc |cm c| ||e 'eo.| /J |e|o.e
J|o|co |cx |e |cm o| ||e |e|| e|cm o (:|.|
||J ||e ce o| ||e |o|| e|cm o ||J /J
|e|o.e | |||e
C07622124.indd 78 9/9/05 9:47:02 AM
Chapter 7. working with Source Code 79
N Ouick kepIace Works like Ouick Find, buL opLionally replaces each occurrence o Lhe
Find LexL wiLh given Replace LexL. Use Lhese commands Lo move Lhrough each
search resulL.
N lind Next Advances Lo Lhe nexL occurrence o Lhe Find LexL. No replacemenL occurs.
N kepIace Replaces Lhe currenL insLance o Lhe Find LexL, Lhen advances Lo Lhe nexL
occurrence.
N kepIace AII Searches Lhe enLire scope or Lhe Find LexL and replaces each insLance
wiLh Lhe Replace LexL. When Lhis process is compleLe, Lhe ediLor will display an
unsaved version o each changed ile. 1his is so you can undo Lhe Replace All or save
only Lhe iles you wanL.
N lind ln liIes Searches or all occurrences o a given sLring in Lhe currenL documenL, all
open documenLs, or Lhe currenL Web siLe. ou can also resLricL Lhe search by ilename
exLension. 1his command diers rom Ouick Find in Lwo primary ways.
N Unlike Ouick Find, Lhis command can'L search or occurrences one aL a Lime. lL always
perorms a Search All.
N 1he Find ln Files command doesn'L open any iles LhaL conLain Lhe given LexL. lnsLead,
iL lisLs Lhe ilename and line number o each insLance in your choice o Lwo windows.
Find ResulLs or Find ResulLs 2.
N kepIace ln liIes Searches or LexL jusL like Lhe Find ln Files command, buL opens each
ile LhaL conLains Lhe Find LexL and replaces iL wiLh LexL you speciy.
Like Lhe Find ln Files command, Replace ln Files reporLs each insLance o Lhe Find LexL in
eiLher Lhe Find ResulLs or Find ResulLs 2 window (your choice).
Like Lhe Ouick Replace command, Replace ln Files leaves Lhese iles open and doesn'L
save Lhem. 1haL way, you can undo Lhe changes or save only Lhe iles you wanL.
N lind SymboI Searches or LexL conLained in symbol names you assign Lo variables, pro-
cedure names, and oLher programming iLems. lL won'L ind insLances o Lhe Find LexL LhaL
appear in commenLs or liLerals.
To dispIay any Iine reported in the
lind kesuIts l or lind kesuIts 2
window, doubIe-cIick that report
Iine.
G < C
C07622124.indd 79 9/9/05 9:47:02 AM
80 Microsoft VisuaI web DeveIoper 2005 xpress dition. BuiId a web Site Now!
lormatting Source Code
When you add, relocaLe, conigure, or deleLe Web page conLrols in Design view, visual Web
Developer naLurally updaLes your H1ML code. ln so doing, iL ollows predeined rules or
indenLing cerLain Lags, adding line breaks, and oLherwise ormaLLing iLs code.
MosL developers wanL visual Web Developer Lo use Lhe same rules Lhey ollow when
ediLing H1ML by hand. l visual Web Developer isn'L ormaLLing H1ML Lhe way you wanL,
proceed as ollows.
TO ST kULS lOk HTML lOkMATTlNG
$

C|oose Cp|ors on |e Too|s nerJ
%
\|er |e Cp|ors d|a|og bo. s|o.r |r ||gJe 8 appeas. oper |e Te. |d|o ard |T\| rodes |r
|e ee v|e. a |e |e
;^\jgZ,"-
|| oe| c| ||e (||c J|o|co |cx
.c||o:e ||e |cmo| c| o|| ||| |oo
oJ eve .c|c|
C07622124.indd 80 9/9/05 9:47:03 AM
Chapter 7. working with Source Code 8l
&
Se|ec eac| rode Jrde |T\| ard ev|e. |e se|rgs |a
appea a |e |g| T|ese rodes ae
Q GeneraI Coro|s op|ors o d|sp|ay|rg |T\| |r SoJce v|e. T||s
pea|rs o op|ors|||e saener conp|e|or (|re|||Serse). .od
.app|rg. ard ||re rJnbes|a |ave ro eec or |e saved
|T\|
Q Tabs Coro|s |e sardad Jr| o |rdera|or |o e.anp|e. yoJ
car c|oose .|e|e o ro o |rder. |o. nJc| o |rder. ard
.|e|e o Jse spaces o ab c|aaces o |rder|rg
Q lormat Coro|s |e cap|a||.a|or o ag ard a|bJe ranes.
aJona|c |rse|or o oJoa|or na|s. aJona|c |rse|or o c|os
|rg ags. ard |rse|or o ||re bea|s o ags |a e.ceed a spec||ed
|erg| T|ese coro|s ae v|s|b|e |r ||gJe 8
Q MisceIIaneous Coro|s .|e|e \|sJa| \eb Deve|ope .||| ass|gr
a Jr|oJe |d~ a|bJe o eac| coro| | pases ard .|e|e | eo
nas ary |T\| | pases
Q VaIidation Coro|s .||c| |T\| spec||ca|or \|sJa| \eb
Deve|ope .||| Jse .|er syra.c|ec||rg yoJ code ard .|a ||rd
o eos yoJ .ar | o epo
;^\jgZ,".
|| J|o|co |cx .c||o:e ||e
|cmo| c| |J|v|J:o| |||
|oo oJ eve .c|c|
'
To cor|gJe |e ona|rg ard d|sp|ay op|ors o a
spec||c ag. c||c| |e :cfaUh rode Jrde |T\| ard |er
c||c| |e HU[GdYW]Z]WCdh]cbg bJor T||s d|sp|ays |e Tag
Spec||c Cp|ors d|a|og bo. s|o.r |r ||gJe
(
|r |e ee v|e. bo. a |e |e. se|ec |e ag rane yoJ
.ar o cor|gJe. |er Jse |e coro|s a |e |g| o
spec|y |e se|rgs yoJ .ar |o e.anp|e. spec|y .|e|e |e
ag JsJa||y |as a sepaae c|os|rg ag (|||e p> p>).
.|e|e o |rse ||re bea|s beoe ard ae |e ag. .|e|e
o |rder |e ag corers. .|e|e o erab|e oJ||r|rg. ard
.|a co|o o Jse .|er d|sp|ay|rg |e ag
)

C||c| |e C? bJor o save yoJ c|arges
lf you want to reformat some
existing HTML code, seIect it
in Source view, then right-cIick
the seIection and choose lormat
SeIection from the shortcut menu.
To seIect the entire page, press
CtrI+A.
G < C
C07622124.indd 81 9/9/05 9:47:04 AM
82 Microsoft VisuaI web DeveIoper 2005 xpress dition. BuiId a web Site Now!
Locating More diting Commands
1he FdiL menu provides a number o useul commands on iLs Advanced submenu. 1o use
any o Lhese commands, selecL Lhe code you wanL Lo modiy, choose Advanced rom Lhe FdiL
menu, and Lhen selecL Lhe command you wanL.
1he H1ML Source FdiLing 1oolbar provides rapid access Lo six commands LhaL previous
secLions have already described. 1o display or hide Lhis Loolbar, choose 1oolbars rom Lhe
view menu and Lhen choose H1ML Source FdiLing.
1he 1exL FdiLor 1oolbar provides buLLons or our lnLelliSense commands, our LexL ediLing
commands, and eighL bookmarking commands. Unlike Lhe H1ML Source FdiLing Loolbar, Lhis
Loolbar works wiLh any Lype o code. 1o display iL, choose 1oolbars rom Lhe view menu, and
Lhen choose 1exL FdiLor.
Storing, CompiIing, and PubIishing Program Code
Sooner or laLer, mosL Web siLe developers wriLe MicrosoL visual 8asic .NF1, C#, or J# pro-
gram code LhaL runs on Lhe Web server. l and when you do Lhis, you can choose eiLher o
Lwo places Lo sLore your program code.
N ln-Line WiLh Lhis approach, Lhe program code or a Web page resides in Lhe same ile as
Lhe H1ML. Speciically, iL resides beLween <scripL runaL="server"> and </scripL> Lags.
1o use Lhis approach, make sure Lhe Place Code ln SeparaLe File check box is cleared
when you creaLe a new Web page and Lhe Add New lLem dialog box appears.
N Code Behind ln Lhis scenario, you sLore your H1ML code and your program code in di-
erenL iles. For example, Lhe H1ML could be in an .aspx ile, and Lhe C# code in a .cs ile.
1o use Lhis approach, selecL Lhe Place Code ln SeparaLe File check box.
This section presumes that you
have a working knowIedge of ASP.
NT programming. lf you don't,
you shouId probabIy move on to
the next chapter. You don't need
this materiaI to understand the
rest of the book.
ABG 8
C07622124.indd 82 9/9/05 9:47:04 AM
Chapter 7. working with Source Code 83
l you choose Lhe Code 8ehind approach, Lhe @ Page direcLive aL Lhe Lop o Lhe new
page will conLain 8dYZ;^aZ and >c]Zg^ih aLLribuLes as shown below.
<x0 Page Language=C# AufoLvenfW1eup=fue
CodeI1]e=mypage.aspx.cs lnhe1fs=mypage x>
1he 8dYZ;^aZ aLLribuLe speciies Lhe name o Lhe ile LhaL conLains Lhe program source
code. 1he >c]Zg^ih aLLribuLe speciies Lhe class name coded as ollows in C#.
pub]1c paf1a] c]ass mypage : 5ysfem.Web.ul.Page
{
}
or like Lhis in visual 8asic .NF1.
Paf1a] C]ass mypage
lnhe1fs 5ysfem.Web.ul.Page
l all your program source code resides in-line, or in a older named VeeTXdYZ jusL inside
your siLe's rooL, you don'L have Lo Wj^aY (or compile) your siLe beore running iL locally
or copying iL Lo anoLher server. ASP.NF1 will compile each ile Lhe irsL Lime a Web visiLor
requesLs a page LhaL needs iL. 1his saves you a sLep, buL iL means LhaL your program source
code musL be presenL on any Web server LhaL runs your siLe.
l your program source code resides anywhere else, you'll need Lo choose 8uild Web SiLe
rom Lhe 8uild menu, and Lhen be sure Lo upload Lhe resulLing /W^c older along wiLh Lhe
resL o your siLe. ou won'L, however, need Lo upload your program source iles, Lhis may
reduce Lhe risk o LheL or Lampering.
lf you move the code-behind fiIe
to another foIder, you must cor-
rect the 8dYZ;^aZ attribute in the
@ EV\Z directive.
lf you rename the .aspx fiIe, you
must aIso rename the code-behind
fiIe and rename the code-behind
cIass name.
G < C
C07622124.indd 83 9/9/05 9:47:05 AM
84 Microsoft VisuaI web DeveIoper 2005 xpress dition. BuiId a web Site Now!
ln Summary.
When ediLing source code such as H1ML, XML, CSS, and program code, visual Web
Developer uses Lhe same proessional ediLor as ull versions o visual SLudio. 1his gives you
ull access Lo proessional ediLing eaLures such as color coding, ouLlining, spliL view, going Lo
a line number, bookmarking, a Lask lisL, lnLelliSense, synLax checking, and code ormaLLing.
1he nexL chapLer explains when iL mighL be aLLracLive Lo creaLe your own server conLrols
and Lhen how Lo do jusL LhaL.
C07622124.indd 84 9/9/05 9:47:05 AM
85
6eXTg\aZTaW7Xf\Za\aZ
JXUHfXe6bageb_f+)
4WW\aZJXUHfXe
6bageb_fgbTCTZX++
Hf\aZJXUHfXe6bageb_f
8YYXVg\iX_l,#
6[TcgXe+
6eXTg\aZTaW
Hf\aZJXU
HfXe6bageb_f
Web pages in Lhe same siLe oLen use sLandard visual componenLs such as
headers, menu bars, and ooLers. 1ypically, Lhese componenLs are idenLical,
or nearly so, rom page Lo page. 1his uniies Lhe siLe and improves overall
conLinuiLy.
MosL experienced developers develop such componenLs once, Lhen
use Lhe resulLs on mulLiple pages. 1his guaranLees uniormiLy and simpliies
mainLenance. When laLer changing Lhe siLe, Lhe developer updaLes one
cenLral copy and Lhe resulLs appear on each page.
MicrosoL

ASP.NF1 2.0, and Lhereore MicrosoL visual Web


Developer", have Lwo eaLures LhaL are especially useul or implemenLing
sLandardized conLenL.
N web User ControIs Display areas o sLandard or programmed conLenL
wiLhin a page.
N Master Pages Fill an enLire page wiLh sLandard or programmed conLenL,
excepL or one or more open areas where variable conLenL can appear.
1he resL o Lhis chapLer will explain how Lo creaLe and use Web user
conLrols. 1he nexL chapLer will explain when and how Lo use masLer pages.
-
C08622124.indd 85 9/9/05 9:48:42 AM
86 Microsoft VisuaI web DeveIoper 2005 xpress dition. BuiId a web Site Now!
Creating and Designing web User ControIs
Any Lime you wanL Lhe same conLenL (or nearly Lhe same conLenL) Lo appear wiLhin mulLiple
pages, consider using a Web user conLrol. CreaLing one o Lhese conLrols is almosL like creaL-
ing a Web page.
CkATlNG A wB USk CONTkOL
$

|r \|sJa| \eb Deve|ope. oper |e s|e |a .||| d|sp|ay |e Jse coro|
%

C|oose BYk:]`Y on |e |||e nerJ
&

\|er |e /dd Ne. |en d|a|og bo. appeas. ||| oJ |ese on |e|ds
Q TempIates Se|ec \eb |se Coro|
Q Name Spec|y a ||erane o |e coro| T|e deaJ| ard eoJ|ed ||erane e.ers|or |s asc.
Q Language C|oose |e |argJage o ary pogan code yoJ p|ar o .|e \|coso \|sJa| |as|c

. \|sJa|
C+

. o \|sJa| +

\|er |r doJb. c|oose |e sane |argJage |a yoJ Jsed o |e es o |e s|e


Q PIace Code ln Separate liIe Se|ec ||s bo. | yoJ .ar o |eep |e |T\| code ard |e pogan code
o ||s coro| |r sepaae ||es C|ea | o |eep bo| ||rds o code |r |e asc. ||e
'

C||c| |e 5XX bJor o ceae |e coro|
C08622124.indd 86 9/9/05 9:48:42 AM
Chapter 8. Creating and Using web User ControIs 87
ou add conLrols Lo a Web user conLrol jusL as you'd add Lhem Lo a Web page. ou can
drag Lhem rom Lhe 1oolbox, inserL Lhem using Lhe LayouL menu, or use any oLher meLhod
LhaL ChapLer 6 described. 1he ollowing procedure, or example, creaLes a Web user conLrol
LhaL displays Lhe currenL daLe.
TO CkAT A wB USk CONTkOL TO DlSPLAY TH CUkkNT DAT
$

|s|rg |e oJsep pocedJe desc|bed above. ceae a re. \eb Jse coro| raned HcXUm=g"UgWl
%

D|sp|ay |e IdYVn>h#VhXm coro| |r Des|gr v|e.
&

Se |e |rse|or po|r |r |e op |e core o |e ed||rg .|rdo.. |er ype HcXUm]g.
'
|oo| |r |e Sardad oo|bo. goJp ard |rd |e |cor o a A^iZgVa coro| Dag ||s |cor oJ o |e
Too|bo. ard dop | ae |e e. on sep ` (Today |s)
(
\a|e sJe |e |ope|es .|rdo. d|sp|ays pope|es o |e re. A^iZgVa coro| @]hYfU`%
Sysen\eb||\ebCoro|s||ea|
)

|s|rg |e pope|es .|rdo.. c|arge |e va|Je o |e >9 popey on A^iZgVa& o a^iIdYVn>h
*
C||c| |r |e na|r ed||rg .|rdo.. |er pess :+ T||s d|sp|ays |e \eb Jse coro|'s pogan code |r
SoJce v|e.
+

T.o dopdo.r ||ss s|oJ|d ro. appea a |e op o |e ed||rg .|rdo.
C08622124.indd 87 9/9/05 9:48:43 AM
88 Microsoft VisuaI web DeveIoper 2005 xpress dition. BuiId a web Site Now!
Q |o \|sJa| |as|c N|T. se|ec |age |r |e |e dopdo.r ||s ard |oad |r |e |g| dopdo.r ||s T|er. ype
|e saener s|o.r be|o. |r geer (\|sJa| \eb Deve|ope sJpp||es |e code s|o.r |r rona| e.)
Pofecfed 5ub PageLoad18yva] sende As Ob1ecf.
8yva] e As 5ysfem.LvenfAgs}
]1f1odayls.1exf = Dafe11me.1oday.1oLongDafe5f1ng
Lnd 5ub
Q |o C+. se|ec Today|s |r |e |e dopdo.r ||s ard |age_|oad(ob|ec serde. |ver/gs e) |r |e |g|
dopdo.r ||s T|er. ype |e saener s|o.r be|o. |r geer (\|sJa| \eb Deve|ope sJpp||es |e code
s|o.r |r rona| e.)
pofecfed vo1d PageLoad1ob1ecf sende. LvenfAgs e}
{
]1f1odayls.1exf = Dafe11me.1oday.1oLongDafe5f1ng1}
}
T|e saener yoJ ype ges |e cJer dae on |e opea|rg sysen. onas | o d|sp|ay. ard
soes |e esJ| |r |e A^iZgVa coro| yoJ added |r seps 4. '. ard b
,
C|oose GUjYHcXUm=g"UgWl on |e |||e nerJ o save |e coro| T|e re. sec|or .||| e.p|a|r |o.
o es |
Adding web User ControIs to a Page
ou can add a Web user conLrol Lo any ASP.NF1 Web page in Lhe same siLe. 1he procedure is
remarkably simple.
C08622124.indd 88 9/9/05 9:48:43 AM
Chapter 8. Creating and Using web User ControIs 89
TO ADD A wB USk CONTkOL TO AN ASP.NT wB PAG
$

Cper |e /S|N|T page |a yoJ .ar o d|sp|ay |e \eb Jse coro|
%
Dag |e \eb Jse coro| on |e So|J|or |.p|oe .|rdo. ard dop | |r p|ace or |e oper
\eb page
1o LesL Lhe Web user conLrol, righL-click any page LhaL conLains Lhe conLrol and choose
view ln 8rowser rom Lhe shorLcuL menu. 1his should produce resulLs like Lhose shown in
Figure 8-.
You can aIso add one web user
controI to another web user
controI.
G < C
;^\jgZ-"&
GbgXfgTJXUhfXeVbageb_W\fc_TlTcTZX
g[TgVbagT\af\g!
C08622124.indd 89 9/9/05 9:48:44 AM
90 Microsoft VisuaI web DeveIoper 2005 xpress dition. BuiId a web Site Now!
Using web User ControIs ffectiveIy
Web user conLrols are generally easy Lo use. NeverLheless, problems can arise. 1he Lopics in
Lhis secLion answer some common quesLions and provide advice or dealing wiLh some Lypi-
cal problems.
Understanding web User ControI Tags
1he irsL Lime you add a given Web user conLrol Lo a page, visual Web Developer adds
Lwo Lags.
N An @ GZ\^hiZg Tag 1his Lag appears above Lhe H1ML source code or Lhe page. lL asso-
ciaLes a Web user conLrol's ilename wiLh a Lag preix and name. Here's an example.
<x0 Reg1sfe 5c=1odayls.ascx
1agName=1odayls 1agPef1x=uc1 x>
A Web user conLrol needs only one such declaraLion per page, even i Lhe conLrol
appears several Limes.
N A web User ControI Tag 1his Lag appears where you wanL Lhe Web user conLrol Lo
appear on Lhe page. 1he Lag preix and name rom Lhe @ GZ\^hiZg declaraLion idenLiy
Lhe Lype o conLrol. Here's an example.
<uc1:1odayls lD=1odayls1 unaf=seve />
A page requires one Lag like Lhis or each insLance o Lhe Web user conLrol iL displays.
O course Lhe browser doesn'L receive eiLher Lhe @ RegisLer direcLive or Lhe Web user
conLrol Lag. 1hese Lags simply Lell ASP.NF1 Lo load a Web user conLrol objecL inLo memory
on Lhe Web server.
When ASP.NF1 sends Lhe page Lo Lhe Web visiLor, iL Lells Lhe Web user conLrol objecL
Lo render iLsel as H1ML. 1his H1ML, and noL Lhe original Lag, is whaL ASP.NF1 sends Lo Lhe
Web visiLor.
C08622124.indd 90 9/9/05 9:48:45 AM
Chapter 8. Creating and Using web User ControIs 9l
Using CSS StyIes in web User ControIs
When designing a Web user conLrol, keep in mind LhaL ASP.NF1 will merge Lhe conLrol's ouL-
puL inLo Lhe <body> secLion o any Web page LhaL uses Lhe conLrol. As a resulL, Lhe Web
user conLrol has no <head> secLion o iLs own, no <body> and </body> Lags, and so orLh.
1his is parLicularly noLiceable i, like mosL experienced Web developers, you use CSS
sLyles Lo ormaL your pages. 8ecause page-speciic sLyles and links Lo shared sLyle sheeL iles
usually reside in Lhe <head> secLion, your sLyle rules generally won'L be available when you
design a Web user conLrol. 1his leads Lo a less-Lhan WSlWC experience. 1here are Lwo
alLernaLives or dealing wiLh Lhis issue.
N Apply CSS sLyles as usual, ignoring Lhe acL LhaL Lhey don'L seem Lo be Laking eecL.
1o check Lhe conLrol's inished appearance, browse a page LhaL conLains iL.
N Add a <sLyle></sLyle> block, links Lo shared sLyle sheeLs, or boLh Lo Lhe Web user con-
Lrol. 1his will make ediLing easier, buL iL may add redundanL or unwanLed sLyles Lo pages
LhaL use Lhe conLrol.
Keep in mind LhaL when several pages use Lhe same user conLrol, each page can have iLs
own sLyles. ln such cases, a Web user conLrol LhaL uses CSS sLyles Lakes on Lhe appearance
o each page. 1his is one reason LhaL visual Web Developer doesn'L Lry Lo apply deaulL CSS
sLyles Lo Web user conLrols.
Adjusting keIative UkLs
When several pages use Lhe same Web user conLrol and Lhose pages reside in dierenL
olders, relaLive URLs LhaL work or one page may noL work in anoLher. For example.
N For a page LhaL resides in Lhe applicaLion rooL, displaying Lhe company logo mighL
require Lhis Lag.
<1mg sc=1mages/]ogo.g1f>
N For a page LhaL resides in an applicaLion subolder, displaying Lhe same logo would
require Lhis Lag.
<1mg sc=../1mages/]ogo.g1f>
C08622124.indd 91 9/9/05 9:48:45 AM
92 Microsoft VisuaI web DeveIoper 2005 xpress dition. BuiId a web Site Now!
1his is a problem i you hard-code relaLive locaLions in <img src="."> and <a hre=".">
Lags wiLhin a Web user conLrol. Any relaLive paLh you code will be wrong i Lhe Web page
using Lhe conLrol resides in a dierenL older Lhan you expecL.
1o avoid Lhis, code any <img> and <a> Lags LhaL use relaLive paLhs wiLh runaL="server"
aLLribuLes, and begin Lhe relaLive locaLion wiLh a Lilde (~) and a slash (/). Here are some
examples.
<a hef=~/company1nfo.aspx unaf=seve>
<1mg sc=~/1mages/]ogo.g1f unaf=seve></a>
When ASP.NF1 renders Lhese conLrols, iL replaces Lhe Lildes (~) wiLh Lhe paLh Lo Lhe
applicaLion rooL. l, or example, Lhe rooL is /myapplicaLion, Lhe Lags will look like Lhis when
Lhe browser receives Lhem.
<a hef=/myapp]1caf1on/company1nfo.aspx>
<1mg sc=/myapp]c1af1on/1mages/]ogo.g1f></a>
8ecause Lhe hre= and src= locaLions are now relaLive Lo Lhe applicaLion rooL, Lhey'll
work correcLly wherever Lhe pages reside.
Coding Attributes for web User ControIs
1he program code in a Web user conLrol can make use o aLLribuLes you code in Lhe Lag LhaL
loads Lhe conLrol. For example, you could wriLe Lhe program code or Lhe IdYVn>h conLrol in
visual 8asic .NF1 like Lhis.
Pub]1c DafeIomaf As 5f1ng

Pofecfed 5ub PageLoad18yva] sende As Ob1ecf.
8yva] e As 5ysfem.LvenfAgs}
lf LCase1DafeIomaf} = shof 1hen
]1f1odayls.1exf = Dafe11me.1oday.1o5hofDafe5f1ng1}
L]se
]1f1odayls.1exf = Dafe11me.1oday.1oLongDafe5f1ng1}
Lnd lf
Lnd 5ub
DecIaring a variabIe or function as
EjWa^X {or, in C#, as ejWa^X) makes
it accessibIe outside the cIass that
decIares it. Eg^kViZ {or eg^kViZ)
variabIes and functions are onIy
accessibIe within the cIass that
decIares them.
ABG 8
C08622124.indd 92 9/9/05 9:48:45 AM
Chapter 8. Creating and Using web User ControIs 93
8ecause iL's EjWa^X, Lhe 9ViZ;dgbVi variable will receive Lhe value o any 9ViZ;dgbVi=
aLLribuLe you code on Lhe Lag LhaL loads Lhe conLrol. ln Lhe ollowing example, Lhe irsL <jX'/
IdYVn>hKW> Lag displays a long daLe (Lhe deaulL) and Lhe second displays a shorL daLe.
<x0 Reg1sfe 5c=1odayls.ascx 1agName=1odayls 1agPef1x=uc2 x>
<uc2:1odaylsvb lD=1odaylsvb1 unaf=seve />
<uc2:1odaylsvb lD=1odaylsvb2unaf=seve DafeIomaf=shof />
l you know how Lo wriLe Lhe necessary visual 8asic or C# program code, you can also
use public properLies Lhis way.
ln Summary.
Web user conLrols provide a quick and easy way o creaLing conLenL once and using iL
on mulLiple Web pages. 1o creaLe a Web user conLrol, you sLarL rom a Web User ConLrol
LemplaLe and Lhen add conLenL jusL as you would Lo a compleLe Web page. 1o include Lhe
conLrol's conLenL on an ASP.NF1 page, irsL open Lhe page in Design view, Lhen drag Lhe
conLrol rom SoluLion Fxplorer and drop iL inLo place. Web user conLrols have a .ascx ile-
name exLension.
1he nexL chapLer will explain how Lo use MasLer Pages, anoLher means o replicaLing
conLenL Lo many pages.
C08622124.indd 93 9/9/05 9:48:46 AM
C08622124.indd 94 9/9/05 9:48:46 AM
95
6eXTg\aZT@TfgXe
CTZX,)
4cc_l\aZ@TfgXeCTZXf
gb6bagXagCTZXf$##
Hf\aZ@TfgXeCTZXf
8YYXVg\iX_l$#&
|o|e
Hf\aZ@TfgXe
CTZXfgb6XageT_\mX
CTZX?Tlbhg
Web user conLrols are very useul or designing repeLiLive layouLs once and
Lhen using Lhem in many pages. 1heir sLrengLh lies in replicaLing parLs o
pages, Lhey're noL as useul or replicaLing Lhe layouL o an enLire page. 1o
undersLand why Lhis is so, consider Lhe sLrucLure o an overall siLe design.
N 1he predominanL design elemenLs usually occupy Lhe edges o each
page. Web user conLrols usually reside in Lhe middle o Lhe page or
along a small porLion o one edge.
N A siLe-level design oLen includes sLyle sheeL iles, scripLs, and oLher ele-
menLs LhaL should appear in Lhe <head> secLion o each page. Web user
conLrols don'L have a <head> secLion and unless you do some complex
programming, Web user conLrols don'L aecL Lhe <head> secLion o Lhe
pages LhaL conLain Lhem.
BVhiZgEV\Zh, a new eaLure o ASP.NF1 2.0, are much beLLer Lhan Web
user conLrols or conLrolling Lhe overall appearance o a siLe. MasLer pages
conLrol every aspecL o a page ZmXZei Lhose areas you designaLe Lo presenL
variable conLenL. MasLer pages are Lrue page LemplaLes, noL jusL page
segmenLs.
.
C09622124.indd 95 9/9/05 9:51:38 AM
96 Microsoft VisuaI web DeveIoper 2005 xpress dition. BuiId a web Site Now!
A XdciZcieV\Z is any page LhaL uses a masLer page. Fach Lime a visiLor requesLs a
conLenL page, ASP.NF1 loads Lhe masLer page, merges in whaLever Lhe conLenL page
provides, and sends Lhe combined resulL Lo Lhe Web visiLor. Merging Lhe masLer page and
Lhe conLenL page on Lhe ly (LhaL is, every Lime a visiLor requesLs Lhe page) has Lwo
imporLanL consequences.
N 1he visiLor always receives currenL versions o boLh Lhe masLer page conLenL and Lhe
conLenL page conLenL.
N 1he merged page has all Lhe capabiliLies o any convenLional ASP.NF1 page. For example,
masLer pages, conLenL pages, or boLh can conLain whaLever server conLrols or cusLom
programming you wanL. 1his means you can cusLomize any parL o Lhe page on Lhe ly
every Lime a visiLor requesLs Lhe page.
$
|se |e |rsJc|ors |r C|ape ` o ceae a
re. s|e |r a o|de raned Coroso\ag|c
| yoJ .|s| o o||o. |e e.anp|es pec|se|y. ceae a
||e sysen \eb s|e |o.eve. a |oca| o enoe ||S
\eb s|e .||| .o| as .e||
%
De|ee ary \eb pages |e s|e cora|rs |o
e.anp|e. de|ee |e deaJ|asp. page |a
\|coso \|sJa| \eb Deve|ope" ceaes by
deaJ|
&
|r |e Seve |.p|oe .|rdo.. |g|c||c| |e
s|e's oo o|de (\Coroso\ag|c\) ard c|oose
5XXBYk=hYa on |e s|ocJ nerJ
Creating a Master Page
1he besL Lime Lo plan masLer pages is when you sLarL planning a new siLe. ln Lhis book, Lhe
siLe will be a or a icLiLious business named ConLoso Magic. HypoLheLically, Lhis business
provides equipmenL and services or sLage magicians. 1o creaLe Lhis siLe using masLer pages,
ollow Lhese sLeps.
TO CkAT A SlT USlNG MASTk PAGS
C09622124.indd 96 9/9/05 9:51:39 AM
Chapter 9. Using Master Pages to CentraIize Page Layout 97
' \|er |e /dd Ne. |en d|a|og bo. appeas. ||| | oJ |||e ||s
Q TempIates Se|ec \ase |age
Q Name /ccep |e deaJ| rane \ase|agenase
Q Language C|oose yoJ avo|e pogann|rg |argJage \|coso \|sJa| |as|c

. \|sJa| C+

. o
\|sJa| +

T|e sanp|e code Jses \|sJa| C+


Q PIace Code ln Separate liIe To epodJce |e sanp|e s|e. c|ea ||s bo.
( C||c| |e 5XX bJor o ceae |e nase page.
8y deaulL, visual Web
Developer creaLes a masLer
page LhaL's blank excepL or one
8dciZciEaVXZ=daYZg conLrol. 1his
Lype o conLrol reserves space
or variable conLenL. Figure 9-
illusLraLes Lhe deaulL masLer page.
;^\jgZ."&
/ ew mo|e ooe .c|o| c|/ ce
e|eme| o c|e|||o.e|c|Je .c|c|
||o| e.e|ve vo|o||e .c|e|
lf you wish, you can deIete the
defauIt 8dciZciEaVXZ=daYZg con-
troI, add other 8dciZciEaVXZ=daYZg
controIs, or do both. ach master
page, however, must have at Ieast
one 8dciZciEaVXZ=daYZ controI.
The TooIbox icon for a
8dciZciEaVXZ=daYZ controI appears
in the Standard group, near the
bottom.
G < C
C09622124.indd 97 9/9/05 9:51:40 AM
98 Microsoft VisuaI web DeveIoper 2005 xpress dition. BuiId a web Site Now!
Figure 9-2 shows Lhe
compleLed masLer page or Lhe
ConLoso Magic siLe. For a real siLe,
you'd probably wanL Lo develop
someLhing more aLLracLive buL
Lhis simple design is enough Lo
show Lhe capabiliLies o visual
Web Developer.
Designing a masLer page
is very much like designing a
normal ASP.NF1 page. All Lhe
Lechniques rom ChapLers 6 and 7
apply. 1he sample design uses
Lhree H1ML Lables, each wiLh
WdgYZg and XZaaheVX^c\ seL Lo zero
(0) and l^Yi] seL Lo 00 percenL.
1he irsL Lable displays Lhe
page banner. lL has Lhree rows
and Lhree columns, used as
ollows.
;^\jgZ."'
c: .o Je|o mo|e ooe |:| o
/c: wc:|J |J|v|J:o| .c|e| ooe
|cweve. /c: m:| |.|:Je o| |eo|
ce c|e|||o.e|c|Je .c|c| c
eo.| mo|e ooe
Setting your outermost tabIe
widths to l00 percent ensures
that the web page aIways fiIIs the
browser window. Setting it to a
fixed size, such as 750 pixeIs,
ensures that your height-to-width
ratios remain constant. The choice
is yours.
G < C
N All Lhree cells in Lhe irsL row are merged. 1he merged cell displays a 5x5 pixel Lranspar-
enL ClF ile. 1his reduces Lhe row heighL below LhaL o a deaulL cWhe, characLer. A CSS
rule named WdgYZgimi conLrols Lhe background and onL color.
N ln Lhe middle row.
N 1he leL cell displays an 80x80 pixel logo ile named magichaL.gi.
N 1he middle cell displays Lhe consLanL LexL ConLoso Magic, a line break, and a A^iZgVa
server conLrol named a^i7VccZgI^iaZ.
N 1he righL cell displays a LransparenL ClF ile sLreLched Lo 80x80 pixels. 1his ensures
LhaL Lhe leL and righL cells are Lhe same size, and consequenLly LhaL Lhe middle cell
is always cenLered in Lhe browser window.
C09622124.indd 98 9/9/05 9:51:41 AM
Chapter 9. Using Master Pages to CentraIize Page Layout 99
For all Lhree cells, a CSS rule named WVccZgimi esLablishes Lhe Lypeace, onL size, and
background color.
N 1he Lhird row duplicaLes Lhe irsL row.
1he a^i7VccZgI^iaZ conLrol displays Lhe LexLual name o each page. 1his name comes rom
a properLy named EV\Z#I^iaZ LhaL you assign or each conLenL page. (1he nexL secLion will
explain Lhis urLher.)
ln visual C#, copying Lhe LexLual page name rom Lhe EV\Z#I^iaZ properLy Lo Lhe
a^i7VccZgI^iaZ#IZmiproperLy requires Lhe ollowing code.
<sc1pf unaf=seve>
pofecfed vo1d PageLoad1ob1ecf sende. LvenfAgs e}
{
]1f8anne11f]e.1exf = Page.11f]e
}
</sc1pf>
ln visual 8asic .NF1, doing Lhe same job requires Lhis code.
<sc1pf unaf=seve>
Pofecfed 5ub PageLoad18yva] sende As Ob1ecf.
8yva] e As 5ysfem.LvenfAgs}
]1f8anne11f]e.1exf = Page.11f]e
Lnd 5ub
</sc1pf>
ln each case.
N 1he <scripL runaL="server">.</scripL> Lags deine an in-line code block (LhaL is, a block
o code LhaL resides wiLhin Lhe Web page buL execuLes on Lhe Web server).
N 1he nexL sLaLemenL deines a EV\ZTAdVY evenL handler. 1his evenL occurs (and Lriggers
Lhe evenL handler code) as soon as Lhe page is compleLely loaded inLo memory and
ready or work.
N 1he Lhird sLaLemenL copies Lhe EV\Z#I^iaZ LexL inLo Lhe IZmi properLy o Lhe a^i7VccZgI^iaZ
conLrol or evenLual Lransmission Lo Lhe browser.
lor information about creating
CSS ruIes, refer to Chapter l0,
"Using Cascading StyIe Sheets.
@BE8 < A9 B
C09622124.indd 99 9/9/05 9:51:41 AM
l00 Microsoft VisuaI web DeveIoper 2005 xpress dition. BuiId a web Site Now!
1he second Lable also conLains Lhree columns, buL only one row. Here's how each column
is used.
N 1he irsL column has a widLh o percenL. lL displays Lhe same LransparenL ClF ile as Lhe
irsL Lable, Lhis Lime sLreLching iL Lo pixel wide and 825 pixels high. 1his provides a small
leL margin and keeps relaLively empLy pages rom looking squashed 1he WdgYZgiZmi CSS
rule provides Lhe background and onL colors.
N 1he second column will evenLually conLain a DH1ML menu buL or now iL's empLy. An
H1ML aLLribuLe seLs iLs widLh Lo percenL, buL Lhe same LransparenL ClF ile, now
sLreLched Lo 00 pixels wide and one pixel Lall, acLually conLrols iLs widLh. 1he WdgYZgiZmi
CSS rule provides Lhe background and onL colors.
N 1he Lhird column, which conLains Lhe 8dciZciEaVXZ=daYZg conLrol, has a widLh o 98 per-
cenL. 1his is where Lhe conLenL o each page will appear.
1he Lhird Lable conLains a single cell LhaL displays Lhe page ooLer. A CSS rule named
[ddiZgimi conLrols iLs background color, onL color, and onL size.
O course, you'll design your masLer pages Lo suiL your own needs. 1he only requiremenL
is LhaL each masLer page musL conLain aL leasL one 8dciZciEaVXZ=daYZg conLrol.
lor instructions on adding tabIes,
pictures, and other objects to a
page, refer to Chapter 6, "Creating
and Modifying web Pages.
F 8 8 4? F B
AppIying Master Pages to Content Pages
1he easiesL and besL way o using masLer pages is Lo speciy Lhem when you creaLe a
new page.
TO SPCllY A MASTk PAG
$

Cper |e s|e |a cora|rs |e nase page (T|e re. corer page .||| a|so es|de |r ||s s|e)
%
|r So|J|or |.p|oe. |g|c||c| |e o|de .|ee yoJ .ar |e re. corer page o es|de. |er
c|oose 5XXBYk=hYa on |e s|ocJ nerJ
C09622124.indd 100 9/9/05 9:51:42 AM
Chapter 9. Using Master Pages to CentraIize Page Layout l0l
&
\|er |e /dd Ne. |en d|a|og bo. appeas. ||| | oJ as C|ape b |rsJced |o.eve. be sJe o
spec|y
Q HYad`UhY. \eb |on
Q GY`YWhAUghYfDU[Y. Se|eced
'
C||c| |e 5XX bJor T|er. .|er |e Se|ec / \ase |age d|a|og bo. s|o.r |r ||gJe ` appeas.
se|ec |e nase page yoJ .ar
( To ceae |e page. c||c| |e C? bJor
;^\jgZ."(
Je ||| J|o|co |cx |c e.||/ ||e
mo|e ooe ||o| o ew .c|e| ooe
|c:|J :e
When you view Lhe new page in Design view, Lhe porLions LhaL come rom Lhe masLer
page will be dimmed as shown in Figure 9-4. 1o modiy anyLhing in Lhe dimmed parL o
Lhe page, you musL open and change Lhe masLer page.
C09622124.indd 101 9/9/05 9:51:42 AM
l02 Microsoft VisuaI web DeveIoper 2005 xpress dition. BuiId a web Site Now!
Figure 9-4 also shows a 8dciZci server conLrol LhaL's cdi dimmed. 1his is where you
should add any conLenL unique Lo Lhe page. Don'L worry i Lhis area iniLially seems small, iL
expands Lo iL any conLenL you add.
NoLe Lhe I^iaZ properLy LhaL appears in Lhe ProperLies window. 1his is where you puL Lhe
page LiLle LhaL Lhe masLer page will copy inLo Lhe A^iZgVa#conLrol named a^i7VccZgI^iaZ
;^\jgZ.")
|e /c: Je|o o .c|e| ooe.
o/ mo|e ooe c||c oeo
J|mmeJ
C09622124.indd 102 9/9/05 9:51:44 AM
Chapter 9. Using Master Pages to CentraIize Page Layout l03
Using Master Pages ffectiveIy
Figure 9-5 shows a conLenL page using Lhe masLer page LhaL Lhe preceding secLions
explained how Lo develop. ln addiLion, Lhe page displays some preliminary conLenL.
1o creaLe such a page.
TO CkAT A PAG SHOwlNG PkLlNAkY CONTNT
$
Ceae a page raned podJcsasp.
ard cor|gJe | o Jse |e nase
page raned BVhiZgEV\Z#bVhiZg | reces
say. ee o |e pocedJes ea||e |r ||s
c|ape
%
Type |r |e va|ab|e corer. |er save
|e page
&
||g|c||c| |e page |r So|J|or
|.p|oe ard c|oose J]Yk=b6fckgYf
on |e s|ocJ nerJ
;^\jgZ."*
/| ||e |cwe. .c|e| ooe oJ mo|e
ooe oeo eom|e|/ ||eoo|eJ
C09622124.indd 103 9/9/05 9:51:45 AM
l04 Microsoft VisuaI web DeveIoper 2005 xpress dition. BuiId a web Site Now!
Looking lnside Master Pages
ConLenL pages LhaL use a masLer page iniLially conLain very liLLle source code. Here's a Lypical
example.
<x0 Page Language=C#
MasfePageI1]e=~/MasfePage.masfe
11f]e=Poducfs x>
<asp:Confenf
lD=Confenf1
ConfenfP]aceho]delD=ConfenfP]aceho]de1
Runaf=5eve>
</asp:Confenf>
1he 5EV\Z direcLive speciies Lhe programming language or any ASP.NF1 program
code you add Lo Lhe page, Lhe name o Lhe masLer page ile, and Lhe page LiLle.
1he <asp.ConLenL> Lag speciies iLs own lD, Lhe lD o a 8dciZciEaVXZ=daYZg conLrol in Lhe
masLer page, and Lhe required gjcVi2hZgkZg aLLribuLe. 1his provides a clue Lo Lhe way
masLer pages work.
N 1he masLer page conLains one or more 8dciZciEaVXZ=daYZg conLrols, each wiLh iLs own lD.
N When a conLenL page uses a masLer page, iL should conLain one 8dciZci conLrol or each
8dciZciEaVXZ=daYZg conLrol in Lhe masLer page.
N When a visiLor requesLs Lhe conLenL page, ASP.NF1 merges Lhe conLenLs o each 8dciZci
conLrol inLo Lhe corresponding 8dciZciEaVXZ=daYZg conLrol in Lhe masLer page, Lhen
delivers Lhe resulLs.
NoLe LhaL like a Web user conLrol, a conLenL page LhaL uses a masLer page conLains no
<hLml></hLml> Lags, no <head> secLion, no <body></body> Lags, and no <orm></
orm> Lags. 1he masLer page supplies all o Lhese.
Modifying xisting Pages to Use Master Pages
visual Web Developer has no command or wizard LhaL applies a masLer page Lo an exisLing
Web page. lnsLead, you musL ollow Lhis manual procedure.
C09622124.indd 104 9/9/05 9:51:45 AM
Chapter 9. Using Master Pages to CentraIize Page Layout l05
TO APPLY A MASTk PAG TO AN XlSTlNG wB PAG
$ Ceae a re. corer page |a Jses |e nase page yoJ .ar
% Copy |e corer yoJ .ar on |e o|d page o |e c||pboad
& |ase |e corer on |e c||pboad |ro |e re. page
' De|ee o erane |e o|d corer page. |er erane |e re. ore
l you eel Lhis approach omiLs someLhing necessary rom Lhe page, or i you jusL like
working in Source view, Lry Lhis procedure.
TO APPLY A MASTk PAG TO AN XlSTlNG wB PAG lN SOUkC Vlw
$
|r SoJce v|e.. de|ee evey||rg on |e oper|rg |n|> ag o |e beg|rr|rg o |e corer yoJ
.ar o ea|r `oJ nJs de|ee a |eas |e |n|> ag. |e |ead> sec|or. |e body> ag. ard
ary on> ags
%
De|ee evey||rg |a cones ae |e corer yoJ .ar o ea|r T||s nJs |rc|Jde a |eas ary
on> ags. |e body> ag. ard |e |n|> ag
&
|rc|ose |e ea|red corer .|||r aspCorer> ard aspCorer > ags. na||rg sJe o code
>92. 8dciZciEaVXZ=daYZg>92. ard gjcVi2hZgkZg a|bJes T|e 8dciZciEaVXZ=daYZg>92 a|bJe
nJs spec|y |e rane o a 8dciZciEaVXZ=daYZg coro| |r |e nase page
'
/dd a BVhiZgEV\Z;^aZ2 a|bJe o |e |age d|ec|ve. na||rg sJe |a | po|rs o |e nase
page yoJ .ar
( Tes ard e|re
C09622124.indd 105 9/9/05 9:51:46 AM
l06 Microsoft VisuaI web DeveIoper 2005 xpress dition. BuiId a web Site Now!
Adjusting keIative UkLs
As wiLh Web user conLrols, you'll need Lo Lake precauLions i Web pages in various olders
will use Lhe same masLer page. Speciically, code any <img src=""> and <a hre=""> aLLri-
buLes relaLive Lo Lhe siLe rooL, and precede Lhe paLh wiLh a Lilde (~). Here's an example.
<1mg sc=~/1mages/mag1chaf.g1f>
Modifying Header lnformation
Occasionally, you may wanL conLenL pages Lo override seLLings LhaL appear in Lhe <head>
secLion o a masLer page. 1o do Lhis, add gjcVi2hZgkZg Lo Lhe <head> Lag in Lhe masLer
page, and Lhen add program code in each Web page Lo override Lhe inormaLion you wanL
Lo change. For example, in Lhe masLer page, code.
<head unaf=seve>
and Lhen in Lhe conLenL page, code Lhe ollowing in Lhe EV\ZTAdVY evenL handler. (1he earli-
er secLion LiLled," CreaLing a MasLer Page," showed how Lo add a EV\ZTAdVY evenL handler Lo
a masLer page. 1he procedure or a conLenL page is Lhe same).
Masfe.Page.heade.Mefadafa.Add1keyWods. e]ephanfs}
1his adds a Lag like Lhe ollowing Lo Lhe <head> secLion o Lhe ouLgoing page.
<mefa name=keyWods confenf=e]ephanfs>
ln Summary.
ASP.NF1 masLer pages are essenLially Web page LemplaLes. 1hey Lypically supply ormaLLing
elemenLs such as sLyle sheeLs, headings, and ooLings.
visiLors don'L browse masLer pages direcLly. lnsLead, Lhey browse conLenL pages LhaL
aLLach a masLer page. ASP.NF1 merges any unique conLenL LhaL Lhe conLenL page supplies
inLo Lhe masLer page, Lhen iL delivers Lhe merged resulL Lo Lhe visiLor. 1his makes Lhe siLe
more uniorm and easier Lo mainLain.
1he nexL chapLer will explain how Lo creaLe Cascading SLyle SheeL (CSS) iles in visual
Web Developer.
The BVhiZg object points to the
master page, if any, that a content
page is using.
ABG 8
C09622124.indd 106 9/9/05 9:51:46 AM
l07
9be`Tgg\aZCTZX
8_X`Xagf<aW\i\WhT__l$#+
Hf\aZAT`XWFgl_Xf
4VebffFXiXeT_CTZXf$#,
|o|e 10
Hf\aZ6TfVTW\aZ
Fgl_XF[XXgf
&%
MosL experienced Web developers now use Cascading SLyle SheeLs (CSS) Lo
conLrol Lypography, colors, and many oLher kinds o ormaLLing wiLhin a siLe.
1he reasons are clear. Used properly, CSS provides much more lexibiliLy and
uniormiLy Lhan older meLhods o page ormaLLing.
visual Web Developer" provides a rich and easy-Lo-use environmenL or
assigning CSS sLyle rules Lo individual page elemenLs and or creaLing shared
sLyle sheeL iles. 1his chapLer inLroduces Lhose eaLures.
C10622124.indd 107 9/9/05 9:56:14 AM
l08 Microsoft VisuaI web DeveIoper 2005 xpress dition. BuiId a web Site Now!
lormatting Page Iements lndividuaIIy
;^\jgZ&%"&
|| J|o|co |cx o||e '' ce||e |c ooe e|eme| c
|c |/|e |ee| :|e ||.||o o/ |.c o| ||e |e|| J||o/ o
.cecJ|o oc|me| c| e|||o
1he eighL caLegories along Lhe leL edge o Lhe dialog
box group Lhe various CSS properLies by Lype. 1he resL o Lhe
dialog box changes depending on Lhe caLegory you selecL.
MosL o Lhese seLLings are airly inLuiLive. l you ind one
LhaL isn'L, consulL Lhe builL-in Help or browse Lhe oicial CSS
speciicaLions aL ]iie/$$lll#l(#dg\$HinaZ$8HH
ln Source view, visual Web Developer provides
lnLelliSense

handling or sLyles wiLhin hinaZ2 aLLribuLes.


So, or example.
N When you Lype styIe=, lnLelliSense displays a selecLion lisL
o CSS properLy names.
N ALer you selecL or Lype a properLy name, Lype a colon (.).
1his Lriggers an lnLelliSense display o accepLable properLy
values.
N When you inish selecLing or Lyping Lhe properLy value,
Lype eiLher Lhe closing quoLe (") or a semicolon and a space
(,) l you Lype a semicolon and a space, lnLelliSense once
again displays a lisL o CSS properLy names.
1o speciy CSS sLyles or a speciic page elemenL, irsL selecL iL in Design view and Lhen eiLher.
N Choose SLyle rom Lhe FormaL menu or
N SelecL Lhe SLyle aLLribuLe in Lhe ProperLies window, Lhen click Lhe ellipsis (. . .) buLLon.
ALer you Lake eiLher o Lhese acLions, visual Web Developer displays Lhe SLyle 8uilder
dialog box shown in Figure 0-.
C10622124.indd 108 9/9/05 9:56:16 AM
Chapter l0. Using Cascading StyIe Sheets l09
Using Named StyIes Across SeveraI Pages
Applying CSS properLies Lo individual page elemenLs provides plenLy o lexibiliLy buL noL
much uniormiLy. 1he more pages Lhe siLe conLains, Lhe harder Lhe Lask o keeping onLs and
colors uniorm. ForLunaLely, CSS helps solve Lhe problem wiLh shared sLyle sheeL iles.
Creating a New StyIe Sheet liIe
1he procedure or creaLing a new sLyle sheeL ile is very much like LhaL or creaLing any oLher
Lype o ile.
TO CkAT A Nw STYL SHT llL
$
C|oose BYk:]`Y on |e |||e nerJ o |g|c||c| a o|de |r So|J|or |.p|oe ard se|ec 5XX
BYk=hYa
%
\|er |e /dd Ne. |en d|a|og bo. appeas. se|ec |e Ghm`YG\YYh enp|ae. ove|de |e deaJ| ||e
rane | yoJ .|s|. ard |er c||c| |e 5XX bJor
Creating StyIe Sheet kuIes
ln a sLyle sheeL ile, each sLyle rule musL have a name (or more correcLly, a hZaZXidg). 1his is
how Web pages reer Lo any sLyle rules LhaL Lhe ile conLains.
A hinaZgjaZ consisLs o a name ollowed by a lisL o CSS properLies and values. 1able 0-
lisLs Lhe Lhree Lypes o sLyle names.
lt's customary for styIe sheet fiIes
to reside in the web site's root
foIder.
G < C
C10622124.indd 109 9/9/05 9:56:16 AM
ll0 Microsoft VisuaI web DeveIoper 2005 xpress dition. BuiId a web Site Now!
1here are Lwo ways o adding a named sLyle rule Lo a sLyle sheeL ile. 1hey are.
N 1ype Lhe sLyle name, a space, and a pair o curly braces([}) on a new line aL Lhe end o
Lhe ile, or beLween any Lwo exisLing sLyles.
N Choose Add SLyle Rule rom Lhe SLyles menu. 1his displays Lhe Add SLyle Rule dialog box
shown in Figure 0-2.
l you choose Lo use Lhe Add SLyle
Rule dialog box, conLinue as ollows.
when you YZ[^cZ a styIe ruIe, a
Ieading period {.) identifies a cIass
seIector and a Ieading pound
sign {#) identifies an lD seIector.
However, you shouIdn't code these
Ieading characters when you jhZ a
styIe ruIe.
G < C
;^\jgZ&%"'
|| J|o|co |cx .eo|e ew |/|e :|e || /c:
e.||/ mce ||o ce ome. ||e :|e w||| c|/
o|/ wee o|| ||e ome mo|.|
IVWaZ&%"&
/e c| '' '|/|e |ome
worId wide VisuaI web AppIies to
web Consortium DeveIoper
IneZHZaZXidg FlemenL Name All H1ML elemenLs o Lhe corresponding Lype.
For example, a sLyle rule named iY applies Lo Lhe
conLenL o all <Ld> Lags.
8aVhhHZaZXidg Class Name All Lags coded wiLh a corresponding class=
aLLribuLe. For example, a sLyle rule named
#Zggdg would apply Lo any Lags you code wiLh a
XaVhh2Zggdg aLLribuLe.
>9HZaZXidg FlemenL lD All Lags coded wiLh a corresponding >92 aLLribuLe.
For example, a sLyle rule named WicHjWb^i would
apply Lo any Lag coded >92WicHjWb^i.
C10622124.indd 110 9/9/05 9:56:17 AM
Chapter l0. Using Cascading StyIe Sheets lll
TO US TH ADD STYL kUL DlALOG BOX
$

Se|ec |e ype o sy|e rane yoJ .ar ar ||ener. a C|ass Nane. o ar ||ener |D
%

C|oose o ype |e rane yoJ .ar
&
| yoJ'e cea|rg a c|ass J|e. yoJ car es|c |s scope o a cea|r ag rane |o e.anp|e. a sy|e J|e
raned A>#egZhid .oJ|d app|y or|y o ags coded || c|ass~'peso'> To Jse ||s eaJe
Q Spec|y |e c|ass rane
Q Se|ec |e Cp|ora| ||ener c|ec| bo.
Q Se|ec |e ag rane yoJ .ar on |e Cp|ora| ||ener dopdo.r ||s
'

C||c| |e |g| ao. bJor (>) T||s .||| add |e re. ag rane o |e Sy|e |J|e ||eac|y bo.
(

C||c| |e C? bJor o ceae |e re. sy|e J|e
l you add several sLyle names Lo Lhe SLyle Rule Hierarchy box wiLhouL clicking Lhe OK
buLLon, visual Web Developer will creaLe a rule LhaL applies only i Vaa Lhe given sLyle names
are in eecL. l, or example, Lhe SLyle Rule Hierarchy dialog box conLains.
7$%/(OLQNV
7'H[WHUQDO
$PHQX
1he resulLing sLyle rule would apply only Lo Lags LhaL saLisy all Lhese condiLions.
N 1he Lag is an anchor (hyperlink) coded XaVhh2bZcj.
N 1he anchor resides wiLhin a Lable daLa cell coded XaVhh2ZmiZgcVa.
N 1he Lable daLa cell resides wiLhin a Lable coded XaVhh2a^c`h.
C10622124.indd 111 9/9/05 9:56:17 AM
ll2 Microsoft VisuaI web DeveIoper 2005 xpress dition. BuiId a web Site Now!
1he ollowing H1ML ragmenL illusLraLes Lhis sLrucLure.
7$%/(FODVVOLQNV!
75!
7'FODVVH[WHUQDO!
$FODVVPHQX!
AlLhough Lhe rules o H1ML require Lhe Lable row (<1R>) Lag shown above, LhaL
Lag is irrelevanL Lo Lhe I67A:#a^c`hI9#ZmiZgcVa6#bZcj sLyle rule. 1haL rule conLains no
requiremenLs or resLricLions based on <1R> Lags.
A rule name such as I67A:IG#h]VYZYI9, however, ldjaY be sensiLive Lo <1R> Lags.
lL would only apply Lo Lable daLa cells locaLed wiLhin Lable rows coded XaVhh2h]VYZY, all
wiLhin an H1ML Lable.
Adding Properties to StyIe Sheet kuIes
Once a sLyle rule exisLs, you can add properLies in any o Lhese Lhree ways.
N 8y Lyping (wiLh Lhe help o lnLelliSense).
N 8y selecLing Lhe sLyle rule and choosing 8uild SLyle rom Lhe SLyles menu.
N 8y righL-clicking Lhe sLyle rule and choosing 8uild SLyle rom Lhe shorLcuL menu.
Choosing 8uild SLyle displays Lhe SLyle 8uilder dialog box LhaL Lhe earlier secLion,
"FormaLLing Page FlemenLs lndividually," described. Fill ouL Lhe dialog box as LhaL secLion
insLrucLed, Lhen click Lhe OK buLLon.
Figure 0-8 shows how visual Web Developer displays Lhe sLyle sheeL ile or Lhe ConLoso
Magic masLer page LhaL appeared in Lhe previous chapLer. NoLe Lhe CSS OuLline window aL
Lhe leL. 1his window makes iL easy Lo ind and selecL sLyles locaLed anywhere in Lhe ile.
AIthough StyIe sheet ruIes change the appearance of other objects, they have
no appearance of their own. They're pIain text,abstract specifications. That's
why there's no Design view for styIe sheet fiIes.
ABG 8
C10622124.indd 112 9/9/05 9:56:17 AM
Chapter l0. Using Cascading StyIe Sheets ll3
Using Shared StyIes in Your web Pages
1o use Lhe sLyle rules in a sLyle sheeL ile, you musL link Lhe sLyle sheeL ile and Lhe Web page.
TO LlNK TH STYL SHT llL AND TH wB PAG
;^\jgZ&%"(
|| | |cw V|:o| e| |eve|ce J||o/
o |/|.o| |/|e |ee| |||e || ||e '' (:|||e
w|Jcw Jce| oeo. .|cce |c.:me|
(:|||e |cm ||e V|ew me:
$
Cper |e \eb page o nase page |a .|||
Jse |e s|aed sy|e s|ee ||e
%

Ta|e e||e o |ese ac|ors
Q D|sp|ay |e page |r Des|gr v|e.. |er dag |e
sy|e s|ee ||e on So|J|or |.p|oe ard dop |
oro |e oper page
Q Se|ec DCC|\|NT |r |e |ope|es .|rdo..
se|ec |e Sy|eS|ee popey. c||c| |e e|||ps|s
( ) bJor. Jse |e esJ||rg d|a|og bo. o se|ec
|e sy|e s|ee ||e yoJ .ar. ard |er c||c| C|
C10622124.indd 113 9/9/05 9:56:18 AM
ll4 Microsoft VisuaI web DeveIoper 2005 xpress dition. BuiId a web Site Now!
Once you link Lhe sLyle sheeL ile and Lhe page, any sLyle rules wiLh Lype or lD selecLors
(LhaL is, any rules named aLer H1ML Lags or >92 aLLribuLes) will Lake eecL immediaLely.
1o apply a class rule Lo an elemenL, proceed as ollows.
TO APPLY A CLASS kUL TO AN LMNT
$

Cper |e \eb page o nase page. |er se|ec |e e|ener |r Des|gr v|e.
%

|r |e |ope|es .|rdo.. |oo| o a popey raned 8aVhh o 8hh8aVhh
&

Type |e rane o |e sy|e as |e 8aVhh o 8hh8aVhh popey va|Je Dor' ype a |ead|rg pe|od
Many experienced web deveIopers
never assign styIe attributes-par-
ticuIarIy coIors and font attri-
butes-directIy to a page eIement.
lnstead, they aIways use ruIes
from shared styIe sheet fiIes.
AIthough at first this approach
might seem abstract and indirect,
it produces sites that are much
more uniform and much easier to
maintain over time.
G < C
ln Summary.
Cascading SLyle SheeL (CSS) rules modiy Lhe properLies o elemenLs on a Web pages. visual
Web Developer can help you ormulaLe Lhese rules graphically (using dialog boxes) or as
LexL (using lnLelliSense).
AlLhough you can speciy CSS properLies or individual page elemenLs, sLoring CSS rules
in sLyle sheeL iles and linking Lhose iles Lo mulLiple pages (such as all Lhe pages in your
siLe) will imparL a more uniorm and proessional appearance. NeverLheless, visual Web
Developer supporLs boLh meLhods o sLoring and applying sLyles.
1he nexL chapLer will explain how Lo creaLe and use ASP.NF1 Lhemes and skins, Lwo more
ways o cenLrally conLrolling a siLe's appearance.
C10622124.indd 114 9/9/05 9:56:19 AM
ll5
6[TcgXe$$
6bageb__\aZ
4ccXTeTaVXj\g[
4FC!A8GG[X`Xf
&&
1he previous chapLer explained how Cascading SLyle SheeLs (CSS) conLrol Lhe
appearance o H1ML elemenLs. CSS can conLrol almosL any visual aspecL o an
H1ML elemenL and, in Lhe case o Lype selecLors, iL can do so wiLhouL any
addiLional code in Lhe elemenL iLsel. For example, a CSS rule named Ld auLo-
maLically aecLs every <Ld> Lag in Lhe same page.
UnorLunaLely, Lhe same approach doesn'L work wiLh ASP.NF1 Web server
conLrols. CSS can aecL any H1ML code LhaL a Web server conLrol creaLes, buL
iL can'L aecL Lhe server conLrol iLsel. 1o cenLrally conLrol Lhe appearance o
Web server conLrols LhroughouL a page or siLe, you need ASP.NF1 2.0 I]ZbZh.
1hemes are a new and powerul eaLure o MicrosoL

ASP.NF1 2.0. 1his


chapLer will explain how Lo use Lhem.
6eXTg\aZ4FC!A8G
G[X`Xf$$)
4WW\aZF^\afgbTa
4FC!A8GG[X`X$$)
4WW\aZ6FFFgl_X
F[XXgfgbTa4FC!A8G
G[X`X$$,
4cc_l\aZG[X`Xfgb
CTZXfTaWF\gXf$%#
The Theme feature in ASP.NT 2.0 is a new technoIogy. lor exampIe, it has
nothing to do with the Themes features in Microsoft lrontPage

2003,
Microsoft Office XP, or Microsoft windows

SharePoint

Services l.0.
ABG 8
C11622124.indd 115 9/30/05 5:13:24 PM
ll6 Microsoft VisuaI web DeveIoper 2005 xpress dition. BuiId a web Site Now!
Creating ASP.NT Themes
A web site can contain as many
themes as you want, just keep cre-
ating subfoIders within
App_Themes.
G < C
Like CSS sLyle sheeLs, a Lheme has no visual appearance o iLs own. 1hereore you creaLe a
Lheme in Lhe MicrosoL visual Web Developer" LexL ediLor.
TO CkAT A THM lN TH TXT DlTOk
$

Cper |e \eb s|e yoJ .ar o coro| .|| a |ene
%
||g|c||c| |e s|e's oo o|de (sJc| as \Coroso\ag|c\). c|oose 5XX:c`XYf on |e s|ocJ nerJ.
ard |er se|ec H\YaY:c`XYf on |e esJ||rg sJbnerJ / ||s po|r
Q | |e s|e doesr' a|eady cora|r ar /pp_T|enes o|de. \|sJa| \eb Deve|ope .||| ceae ore
Q \|sJa| \eb Deve|ope .||| a|.ays ceae a sJbo|de .|| a rane |||e T|ene1. bJ |eave |a rane
oper o eran|rg
&

|erane |e re. |ene sJbo|de T|e rane yoJ ass|gr .||| becone |e |ene rane
O course, an empLy Lheme older will have no eecL on your siLe. 1o conLrol Lhe
appearance o your siLe, you musL irsL add .skin or .css iles. 1he nexL Lwo secLions explain
how Lo do Lhis.
Adding Skins to an ASP.NT Theme
ln ASP.NF1 2.0, a h`^c[^aZ speciies visual properLies or one or more kinds o Web server con-
Lrol. A single Lheme subolder can accommodaLe as ew or as many skin iles as you like. l
Lhere's more Lhan one ile, ASP.NF1 will read Lhem all as i Lhey were one ile.
Skin iles conLain h`^ciV\h, which are XML code. 1he skin Lag or each Lype o conLrol
should be amiliar. iL's Lhe same as Lhe Lag LhaL appears in a Web page.
C11622124.indd 116 9/30/05 5:13:25 PM
Chapter ll. ControIIing Appearance with ASP.NT Themes ll7
Coding a skin ile is slighLly Ledious because you have Lo do iL in Source view and Lhere's
no lnLelliSense

supporL.
TO CkAT A SKlN llL
$
||g|c||c| |e |ene sJbo|de .|ee yoJ .ar |e s||r ||e o es|de. |er c|oose 5XXBYk=hYa
on |e s|ocJ nerJ
%
\|er |e /dd Ne. |en d|a|og bo. appeas. se|ec |e G_]b:]`Y enp|ae. ove|de |e deaJ| ||e
rane | yoJ .|s|. ard |er c||c| |e 5XX bJor
&

\|sJa| \eb Deve|ope .||| d|sp|ay |e re. s||r ||e |r SoJce v|e.
'

Ceae a ag o eac| ype o coro| yoJ .ar |e s||r o aec |ee ae sone e.anp|es
<asp:Rad1o8uffonL1sf unaf=seve />
<asp:DopDoWnL1sf unaf=seve />
<asp:1exf8ox unaf=seve />
T|ese ae |e sane ag ranes |a appea .|er yoJ add |e coespord|rg \eb seve coro| o a \eb
page | yoJ'e ro sJe .|a o ype. oper o ceae a \eb page |a cora|rs |e ype o coro| yoJ .ar.
ard |oo| a |e coro|'s ag rane |r SoJce v|e.
Dor' oge |e gjcVi2hZgkZg a|bJe ard |e c|os|rg s|as| () |Js |rs|de |e c|os|rg arg|e bac|e
(

\|||r eac| ag. add |e seve coro| a|bJes yoJ .ar
/ga|r. |ese ae |e sane a|bJes |a |e g|ver coro| ecogr|.es |r a \eb page | yoJ'e ro sJe .|a
o ype. oper o ceae a \eb page |a cora|rs |e ype o coro| yoJ .ar. cor|gJe |e a|bJe yoJ
.ar. ard |er s.|c| o SoJce v|e. ard |oo| a |e esJ||rg code
)

\|er yoJ'e dore. c|oose GUjY on |e ||e nerJ
C11622124.indd 117 9/30/05 5:13:25 PM
ll8 Microsoft VisuaI web DeveIoper 2005 xpress dition. BuiId a web Site Now!
ln general, a skin ile can only aecL Lhe appearance o Web server conLrols. lL XVci
conLrol any o Lhe ollowing.
N ASP.NF1 user conLrols.
N Non-visual properLies o Web server conLrols. For example, iL can'L conLrol properLies such
as Click, SelecLedlndexChanged, and FnableviewSLaLe.
N Web server conLrols such as <asp.LiLeral> LhaL have no visual properLies.
N H1ML server conLrols.
N Ordinary H1ML elemenLs.
l necessary, you can deine more Lhan one skin Lag or Lhe same Web server conLrol.
Here's an example.
<asp:DopDoWnL1sf 8ackCo]o=#c9d IoeCo]o=#0000cc
unaf=seve />
<asp:DopDoWnL1sf 8ackCo]o=#d0f0ff IoeCo]o=#000000
unaf=seve 5k1nld=sk1nDd]M1o />
1he irsL Lag above is aYZ[Vjaih`^c because iL has no H`^c>Y2 aLLribuLe. 1he second is a
cVbZYh`^c because iL has a H`^c>Y2 aLLribuLe.
Suppose LhaL Lhese skins are parL o a Lheme named Hbd`Z, and LhaL you have a Web
page using LhaL Lheme. ln LhaL page, Lhe ollowing <asp.DropDownLisL> Lag, which has no
H`^c>Y2 aLLribuLe, would geL Lhe irsL skin shown above.
<asp:DopDoWnL1sf lD=dd]lfem unaf=seve>
<asp:L1sflfem va]ue=a>Ass1sfanf</asp:L1sflfem>
<asp:L1sflfem va]ue=b>81d</asp:L1sflfem>
<asp:L1sflfem va]ue=c>Co1n</asp:L1sflfem>
<asp:L1sflfem va]ue=e>L]ephanf</asp:L1sflfem>
<asp:L1sflfem va]ue=W>Wafch</asp:L1sflfem>
</asp:DopDoWnL1sf>
ASP.NT 2.0 Themes can contain
both skin fiIes and CSS fiIes. lf a
skin fiIe can't controI the attribute
or eIement you want, a CSS fiIe
might offer an aIternative. The
next section wiII expIain how to
use CSS fiIes with ASP.NT 2.0
Themes
G < C
C11622124.indd 118 9/30/05 5:13:26 PM
Chapter ll. ControIIing Appearance with ASP.NT Themes ll9
Conversely, an <asp.DropDownLisL> Lag coded H`^c>Y2h`^c9YaB^ggdg would geL Lhe skin
wiLh LhaL H`^c>Y. For example.
<asp:DopDoWnL1sf lD=dd]lfem unaf=seve
5k1nld=sk1nDd]M1o>
<asp:L1sflfem va]ue=a>Ass1sfanf</asp:L1sflfem>
<asp:L1sflfem va]ue=b>81d</asp:L1sflfem>
<asp:L1sflfem va]ue=c>Co1n</asp:L1sflfem>
<asp:L1sflfem va]ue=e>L]ephanf</asp:L1sflfem>
<asp:L1sflfem va]ue=W>Wafch</asp:L1sflfem>
</asp:DopDoWnL1sf>
1o view any ASP.NF1 2.0 Lheme, you musL apply Lhe Lheme Lo a Web page and Lhen view
Lhe page in a browser. 1he secLion LiLled "Applying 1hemes Lo Pages and SiLes" laLer in Lhis
chapLer explains Lhis procedure in deLail.
Adding CSS StyIe Sheets to an ASP.NT Theme
l you wish, you can also sLore shared CSS sLyle sheeL iles in your Lheme subolders. ASP.NF1
will link Lhese sLyle sheeLs Lo any page LhaL uses Lhe given Lheme and has a gjcVi2hZgkZg
aLLribuLe in iLs <head> Lag.
When you apply a Lheme like Hbd`Z or B^ggdgh Lo a page or siLe, ASP.NF1 includes any
CSS iles LhaL are parL o Lhe Lheme. lL does Lhis by adding <link> Lags Lo Lhe <head> secLion
o Lhe page, V[iZg any exisLing <link> Lags. Suppose, or example, LhaL you have.
N An App_1hemes/Smoke older LhaL conLains a CSS ile named Smoke.css.
N An App_1hemes/Mirrors older LhaL conLains Lwo CSS iles named Mirrors.css and srorriM.
css.
N A runaL="server" aLLribuLe in each <head> Lag, as in.
<head unaf=seve>
</head>
C11622124.indd 119 9/30/05 5:13:27 PM
l20 Microsoft VisuaI web DeveIoper 2005 xpress dition. BuiId a web Site Now!
1hen, ASP.NF1 will add Lhe ollowing sLyle sheeL link Lo any page LhaL uses Lhe Hbd`Z Lheme.
<]1nk hef=App1hemes/5moke/5moke.css fexf=fexf/css
e]=sfy]esheef />
and Lhese links Lo any page LhaL uses Lhe B^ggdgh Lheme.
<]1nk hef=App1hemes/M1os/M1os.css fexf=fexf/css
e]=sfy]esheef />
<]1nk hef=App1hemes/M1os/so1M.css fexf=fexf/css
e]=sfy]esheef />
8ecause ASP.NF1 adds Lheme CSS links aLer any exisLing CSS links.
N Any CSS sLyle rules or properLies you code in a Lheme CSS ile will override like-named
rules or properLies in CSS iles you've manually linked Lo Lhe page.
N l your siLe conLains several Lhemes, Lhere's no need or Lhe CSS iles Lo duplicaLe each
oLher. ou can puL Lhe common rules and aLLribuLes in a convenLionally-linked CSS ile,
and puL jusL Lhe overrides in Lheme CSS iles.
1he graphic aL Lhe leL shows Lhe arrangemenL o skin and CSS iles or Lhree Lhemes in Lhe
ConLosoMagic siLe. AlLhough done here or clariLy, Lhere's no requiremenL LhaL skin iles, CSS
iles, and Lheme subolders have similar names.
Don't forget that ASP.NT 2.0
themes onIy controI web server
controIs. To centraIIy controI the
appearance of anything eIse, you
stiII need to use CSS.
@BE8 < A9 B
AppIying Themes to Pages and Sites
ou can apply Lhemes Lo individual Web pages or Lo an enLire siLe.
TO APPLY A THM TO A SlNGL wB PAG
$
Cper |e page |r \|sJa| \eb Deve|ope

D|sp|ay DCC|\|NT |r |e |ope|es .|rdo.
Se|ec |e T|ene popey. |er c|oose |e
|ene yoJ .ar on |e dopdo.r ||s
Themes you appIy to individuaI
pages override any theme you
appIy to the entire site.
G < C
&
%
C11622124.indd 120 9/30/05 5:13:27 PM
Chapter ll. ControIIing Appearance with ASP.NT Themes l2l
1o speciy a Lheme LhaL applies Lo an enLire Web siLe, you have Lo modiy an XML ile
named web.conig. visual Web Developer creaLes Lhis ile whenever iL creaLes a new siLe.
TO SPCllY A DlAULT THM lOk ALL PAGS lN A SlT
$

Cper |e s|e's .ebcor|g ||e |r \|sJa| \eb Deve|ope
%
|oo| o a pa| o sysen.eb> ard sysen.eb> ags | peser. |ese ags JsJa||y sJoJrd o|e
corer ard appea |g| ae |e cor|gJa|or> ag | yoJ .ebcor|g ||e |as ro oper|rg ard c|os
|rg sysen.eb> ags. ceae |en
&
/dd |e ag s|o.r be|o. |r geer ae |e sysen.eb> ag |ep|ace Hbd`Z .|| |e rane o yoJ
|ene
<?xm] ves1on=1.0 encod1ng=uff-?>
<conf1guaf1on xm]ns=... >
<sysfem.Web>
<pages fheme=5moke />
</sysfem.Web>
</conf1guaf1on>
Figure - and Figure -2 show a page rom Lhe ConLoso Magic siLe as iL looks using
Lwo dierenL Lhemes. Skin iles modiy Lhe appearance o Lhe orm ields and CSS iles modiy
all Lhe oLher elemenLs. 1o view Lhe conLenL o Lhese iles, open Lhem in Lhe sample siLe LhaL
comes wiLh Lhis book.
lf you need heIp obtaining and
instaIIing the sampIe fiIes for this
book, refer to the section titIed,
"Obtaining and lnstaIIing the
SampIe liIes lor This Book, in
Chapter l.
@BE8 < A9 B
C11622124.indd 121 9/30/05 5:13:28 PM
l22 Microsoft VisuaI web DeveIoper 2005 xpress dition. BuiId a web Site Now!
;^\jgZ&&"&
G[\f`bfg_lZeTlJXUcTZXhfXfT
Vhfgb`g[X`XaT`XWSmoke!J\g[
abg[X`X\aXYYXVgg[XVb_befV[X`X
jbh_WeXfX`U_Xg[TgbY9\ZheX,(
\a6[TcgXe,!AbgXg[XV[TaZXf\a
glcbZeTc[lTfjX__!
C11622124.indd 122 9/30/05 5:13:29 PM
Chapter ll. ControIIing Appearance with ASP.NT Themes l23
ASP.NF1 2.0 Lhemes can cenLrally conLrol Lhe appearance o any ASP.NF1 2.0 siLe. WiLhin a
Lheme, skin iles conLrol Web server conLrols and CSS iles conLrol ordinary H1ML elemenLs.
Skin iles conLain XML code LhaL you ediL by hand. 1o modiy Lhe value o a given server
conLrol aLLribuLe, you code Lhe same Lag and aLLribuLe names LhaL appear in Lhe Web page.
1o apply a 1heme Lo a speciic page, modiy Lhe page's 1heme aLLribuLe. 1o apply a 1heme
Lo an enLire Web siLe, add a <pages Lheme="WKHPHQDPH" /> Lag Lo Lhe web.conig ile.
1he nexL chapLer will explain how Lo code a siLe map and Lhen use iL Lo creaLe dynamic
menus, Lree view menus, and breadcrumbs.
;^\jgZ&&"'
;XeXfg[XfT`XcTZXj\g[g[X
Mirrorsg[X`X\aXYYXVg!5e\Z[g
eXY_XVgXWVb_befTeXg[X\afc\eTg\ba!
ln Summary.
C11622124.indd 123 9/30/05 5:13:31 PM
C11622124.indd 124 9/30/05 5:13:31 PM
l25
6[TcgXe$%
?\a^\aZg[XCTZXf
\aLbheF\gX
4hgb`Tg\VT__l
&'
Fvery Web siLe needs an orderly collecLion o hyperlinks LhaL helps visiLors
ind Lheir way Lo Lhe inormaLion Lhey're seeking. ln a large siLe, keeping
Lhese links clear, simple, and well-organized can be a daunLing Lask, parLicu-
larly as developers make changes and apply updaLes occur over Lime. 1o
help wiLh Lhis Lask, ASP.NF1 2.0 provides our new componenLs.
N A Site Map liIe LhaL documenLs Lhe siLe's logical sLrucLure.
N A BZcj ControI LhaL reads Lhe siLe map ile and displays drop-down or
ly-ouL dynamic menus.
N A IgZZK^Zl ControI LhaL reads Lhe siLe map ile and displays an expand-
able, collapsible, indenLed lisL o links.
N A H^iZBVeEVi] ControI LhaL searches Lhe siLe map ile or Lhe URL o
Lhe currenL page, and Lhen displays a series o links (breadcrumbs) LhaL
lead back Lo Lhe home page.
Working LogeLher, Lhese our componenLs make iL very easy Lo organize
your siLe and display your hyperlinks in Lhe mosL up-Lo-daLe, visually
aLLracLive, and compacL way. 1he resL o Lhis chapLer will explain how Lo
make Lhis happen on any siLe you creaLe.
6eXTg\aZTF\gX@TcYbe
LbheJXUF\gX$%)
6eXTg\aZ7ebc7bjaTaW
9_lBhg@Xahf$&$
6eXTg\aZGeXXI\Xj
@Xahf$&&
Cebi\W\aZ
5eXTWVeh`Uf$&'
The use of ASP.NT 2.0 navigation controIs is entireIy optionaI. lf you prefer,
you can create your site structure, hyperIinks, and menus manuaIIy or with a
compatibIe third-party tooI.
< @C BEG4AG
C12622124.indd 125 9/9/05 10:01:08 AM
l26 Microsoft VisuaI web DeveIoper 2005 xpress dition. BuiId a web Site Now!
Creating a Site Map for Your web Site
All Lhree ASP.NF1 2.0 navigaLion conLrols have so many opLions and so much lexibiliLy LhaL
new developers someLimes have Lrouble inding a sLarLing poinL. 1he soluLion, in mosL cases,
is Lo irsL creaLe a siLe map ile. 1he procedure or doing Lhis should be quiLe amiliar.
TO CkAT A SlT MAP llL
$

CdYbh\Yg]hYmcikUbhhcaUdh\YbW\ccgYBYk:]`YZfcah\Y:]`YaYbi"
%

K\Ybh\YBYk=hYaX]U`c[VclUddYUfggY`YWhh\YG]hYAUdhYad`UhY"
&
=Zh\]g]gh\YZ]fghg]hYaUd]bmcifg]hYUWWYdhh\YXYZUi`hZ]`YbUaY"Ch\Yfk]gYcjYff]XYh\Ygi[[YghYX
Z]`YbUaYVUgY"
'

7`]W_h\Y5XXVihhcb"
8y deaulL, Lhis procedure creaLes a ile named Web.siLemap locaLed in Lhe siLe's rooL
older. 1he deaulL name and locaLion are boLh good choices. ln acL, you shouldn'L change
Lhe ile name.
lnLernally, ASP.NF1 2.0 siLe maps are XML iles. MicrosoL visual Web Developer"
Lhereore displays Lhem in LexL mode. OmiLLing commenLs and abbreviaLing Lhe mbach
aLLribuLe (which is consLanL), a new siLe map ile looks like Lhis.
1 <?xm] ves1on=1.0 encod1ng=uff- ?>
2 <s1feMap xm]ns=... >
3 <s1feMapNode u]= f1f]e= desc1pf1on=>
4 <s1feMapNode u]= f1f]e= desc1pf1on= />
S <s1feMapNode u]= f1f]e= desc1pf1on= />
6 </s1feMapNode>
7 </s1feMap>
C12622124.indd 126 9/9/05 10:01:09 AM
Chapter l2. Linking the Pages in Your Site AutomaticaIIy l27
1he ormaL o Lhis ile is relaLively sLraighLorward.
N 1he <xml> Lag on line idenLiies Lhe version o XML in use. Don'L modiy Lhis Lag.
N 1he <siLeMap> Lag on line 2 and iLs closing </siLeMap> Lag on line 7 mark Lhe begin-
ning and end o Lhe XML documenL. Don'L modiy Lhese Lags eiLher.
N Fvery <siLeMap> Lag musL conLain one and only one Lop-level <siLeMapNode> Lag. 1his
deines Lhe sLarLing page in Lhe siLe map-usually Lhe siLe's Home page. ln Lhe example,
Lhis is Lhe Lag on line 8. lLs closing Lag is on line 6.
N 8eLween Lhe Lop-level <siLeMapNode> Lag and iLs closing Lag, you can add as many
addiLional <siLeMapNode> Lags as you like. Fach o Lhese Lags will become "level Lwo"
nodes in your drop-down menu or expandable Lree view. Lines 4 and 5 provide
examples.
N WiLhin each level Lwo <siLeMapNode> Lag you can add as many level Lhree
<siLeMapNode> Lags as you like, and so orLh.
1his is acLually a simple process. JusL visualize how you wanL visiLors Lo navigaLe Lhrough
your siLe, Lhen indenL (or cZhi) a seL o <siLeMapNode> Lags Lhe same way. For example, i
you wanL Lhis logical sLrucLure.
Home Page
ProducLs
Cloaks
Rubber Daggers
Services
Dry Cleaning
vulcanizing
code your <siLeMapNode> Lags like Lhis.
kemember that the forms.
<s1feMapNode />
and
<s1feMapNode></s1feMapNode>
are equivaIent, except that the
second form can encIose addi-
tionaI tags.
G < C
C12622124.indd 127 9/9/05 10:01:09 AM
l28 Microsoft VisuaI web DeveIoper 2005 xpress dition. BuiId a web Site Now!
<s1feMapNode u]=defau]f.aspx f1f]e=home Page>
<s1feMapNode u]=poducfs.aspx f1f]e=Poducfs>
<s1feMapNode u]=c]oaks.aspx f1f]e=C]oaks />
<s1feMapNode u]=dagges.aspx f1f]e=Rubbe Dagges />
</s1feMapNode>
<s1feMapNode u]=sev1ces.aspx f1f]e=5ev1ces>
<s1feMapNode u]=dyc]ean.aspx f1f]e=Dy C]ean1ng />
<s1feMapNode u]=vu]can1z.aspx f1f]e=vu]can1z1ng />
</s1feMapNode>
</s1feMapNode>
1here are only Lhree <siLeMapNode> aLLribuLes Lo consider or now. 1hey are.
N JGA 1he absoluLe or relaLive locaLion o Lhe page. 1his is where Lhe link in your menu or
Lree view will direcL a visiLor, or where Lhe reverse paLh o breadcrumbs will begin.
Don'L speciy Lhe same URL value Lwice in Lhe same siLe map ile. OLherwise, an error
will occur whenever you browse a page LhaL conLains a BZcj, IgZZK^Zl, or H^iZBVeEVi]
(breadcrumb) conLrol.
For relaLive locaLions, iL's besL Lo code a Lilde and slash (~/) ollowed by Lhe paLh rom
Lhe applicaLion rooL. Here are Lwo examples.
u]=~/defau]f.aspx
u]=~/poducfs/Wands.aspx
1o creaLe a <siLeMapNode> LhaL doesn'L link Lo anoLher page, leave iLs URL value blank.
1his is useul or menu iLems LhaL group deeper LargeL pages, buL have no LargeL pages
Lhemselves.
N i^iaZ 1he name o Lhe page in naLural language, such as Home Page or ConLacL Us. 1his
will appear as Lhe visible LexL in your menu, Lree view, or breadcrumb.
N YZhXg^ei^dc A longer descripLion. 1his will appear as Lool Lip LexL when Lhe mouse is over
Lhe link. 1his ield is opLional.
Chapter l7 wiII describe a gdaZ2
attribute you can add to any
<siteMapNode> tag. Combined
with other techniques, this attri-
bute hides menu items that the
current visitor Iacks permission
to access.
F 8 8 4? F B
C12622124.indd 128 9/9/05 10:01:09 AM
Chapter l2. Linking the Pages in Your Site AutomaticaIIy l29
;^\jgZ&'"&
G[\f\f[bjI\fhT_JXU7XiX_bcXe
W\fc_Tlfg[Xf\gX`TcY\_XYbeg[X
6bagbfb@TZ\VJXUf\gX!
Figure 2- shows how visual Web Developer displays Lhe siLe map ile or Lhe ConLoso
Magic siLe. Figure 2-2 shows a ly-ouL menu based on Lhis siLe map. 1he nexL secLion will
explain how Lo creaLe such a menu.
C12622124.indd 129 9/9/05 10:01:10 AM
l30 Microsoft VisuaI web DeveIoper 2005 xpress dition. BuiId a web Site Now!
;^\jgZ&'"'
G[X@XahVbageb_\ag[\fcTZXWXe\iXf
\gffgehVgheXYeb`g[Xf\gX`Tcf[bja
\a9\ZheX$%$!
C12622124.indd 130 9/9/05 10:01:12 AM
Chapter l2. Linking the Pages in Your Site AutomaticaIIy l3l
Creating Drop-Down and lIy-Out Menus
ou can add drop-down or ly-ouL menus Lo masLer pages, Web user conLrols, or individual
pages.
TO CkAT A DkOP-DOwN Ok lLY-OUT MNU
$

CdYbh\YaUghYfdU[YKYVigYfWcbhfc`cfdU[Yh\Uhk]``X]gd`Umh\YaYbi"
%
=bh\YHcc`VclcdYbh\Y8UhU[fcidUbXXfU[UG]hYAUd8UhUGcifWYWcbhfc`cbhch\YcdYbdU[Y"
MciWUbdihh\]gWcbhfc`Ubmk\YfYmcikUbhVih_YYd]hcihcZh\YkUm"=hkcbhX]gd`UmUbmh\]b[k\Yb
UKYVj]g]hcfVfckgYgh\YdU[Y"
J]giU`KYV8YjY`cdYfk]``Ugg][bUbUaYgiW\UgH^iZBVe9HcfH^iZBVe9H&hch\]gWcbhfc`"5gg\ckb
VY`ckh\]gbUaYUddYUfgcbh\YZUWYcZh\YWcbhfc`"Mci``bYYXh\]gWcbhfc`bUaY]bghYd("
&
=bh\YHcc`VclcdYbh\YBUj][Uh]cb[fcidUbXXfU[UAYbiWcbhfc`cbhch\YcdYbdU[Y"8fcd]h
k\YfYjYfmcikUbhh\YaYbihcUddYUf"
'
J]giU`KYV8YjY`cdYfk]``X]gd`UmUhUg_aYbi`]_Yh\YcbYg\ckb]b:][ifY%&!'"CdYbh\Y
7\ccgY8UhUGcifWYXfcd!Xckb`]ghUbXgdYW]Zmh\YbUaYcZh\YG]hYAUd8UhUGcifWYWcbhfc`
mciUXXYX]bghYd&"
(

GUjYh\YdU[Yh\Ybf][\h!W`]W_]hUbXW\ccgYDfYj]Yk=b6fckgYf"
1o urLher conigure Lhe menu, selecL iL and Lhen speciy any values you wanL in Lhe
ProperLies window. 1he OrienLaLion seLLing, or example, selecLs beLween.
N HorizontaI 1op-level menu iLems will appear leL Lo righL. 1he resulL is a drop-down
menu sysLem.
N VerticaI 1op-level menu iLems will appear Lop Lo boLLom. 1his creaLes a ly-ouL menu
sysLem.
;^\jgZ&'"(
4@XahVbageb_fgTf^`XahfcXV\Y\Xf
T`baZbg[Xeg[\aZfj[XeXg[X`Xah
f[bh_WZXg\gf_\fgbY_\a^f!
C12622124.indd 131 9/9/05 10:01:12 AM
l32 Microsoft VisuaI web DeveIoper 2005 xpress dition. BuiId a web Site Now!
1able 2- shows Lhe non-deaulL seLLings in eecL or Lhe menu shown previously in
Figure 2-2.
A static menu item is one that's
aIways visibIe. Dynamic menu
items appear onIy when you seIect
their parent in the menu tree.
ABG 8
IVWaZ&'"&
@XahCebcXeg\Xf\a8YYXVgYbe9\ZheX$%%
1here's noLhing special abouL Lhese seven properLies or Lheir values, yours will be dierenL,
depending on Lhe requiremenLs o your siLe. NeverLheless, Lhese seven illusLraLe some
Lypical choices.
Setting VaIue Description
9ViVHdjgXZ>9 SiLeMapDS 1ells Lhe menu Lo geL iLs links rom Lhe siLe
map ile LhaL Lhe SiLeMapDaLaSource conLrol
named SiLeMapDS speciies.
HiVi^X9^heaVnAZkZah 2 1ells Lhe menu Lo display Lhe irsL Lwo menu
levels aL all Limes. 1he remaining levels
will appear dynamically (LhaL is, only when
selecLed).
HiVi^XHjWBZcj>cYZci (empLy) 1ells Lhe menu noL Lo indenL level Lwo menu
iLems any more Lhan iL indenLs level one
iLems (i.e. Lhe Home page).
HiVi^XBZcj>iZbHinaZ" MenuSLalLm Speciies a CSS rule LhaL conLrols Lhe
8hh8aVhh deaulL appearance o sLaLic menu iLems.
HiVi^X=dkZgHinaZ"8hh8aVhh MenuSLaHov Speciies a CSS rule LhaL conLrols Lhe appear-
ance o sLaLic menu iLems when Lhe mouse is
over Lhem.
9ncVb^XBZcj>iZbHinaZ" MenuDynlLm Speciies a CSS rule LhaL conLrols Lhe
8hh8aVhh deaulL appearance o dynamic menu iLems.
9ncVb^X=dkZgHinaZ" MenuDynHov Speciies a CSS rule LhaL conLrols Lhe
8hh8aVhh appearance o dynamic menu iLems when
Lhe mouse is over Lhem.
C12622124.indd 132 9/9/05 10:01:13 AM
Chapter l2. Linking the Pages in Your Site AutomaticaIIy l33
Speciying CSS rules or Lhe various Lypes o menu iLems ollows Lhe pracLice o
cenLralizing all onL and color decisions in CSS sLyle sheeLs. 1o inish Lhis Lask you musL, o
course, deine Lhe maLching sLyle rules.
l your menu sLrucLure becomes Loo large or Loo complex, you mighL choose Lo use
several siLe map iles insLead o one. For example, you mighL creaLe Lhree separaLe siLe map
iles. or ProducLs, or Services, and or Lhe Home page and all oLher pages. WiLhin each
o Lhese areas, you would Lhen poinL any H^iZBVe9ViVHdjgXZXonLrols (and hence BZcj
conLrols) Lo Lhe appropriaLe siLe map ile.
1he <asp.menu> conLrol is incredibly lexible. For example.
N l you choose DaLa Source. None on Lhe conLrol's Lask menu, you can click Lhe nearby
FdiL Menu lLems link and conigure a seL o menu links manually.
N l you choose a daLa source oLher Lhan a SiLeMapDaLaSource, you can generaLe menus
on Lhe ly based on records in a daLabase. 1o map daLabase ields Lo menu iLems, conig-
ure Lhe Menu conLrol's 9ViV7^cY^c\h properLy.
N ou can easily conigure Lhe colors, onLs, icon iles, and oLher visual properLies o each
Lype o menu iLem.
N l you change a siLe's Lheme, any Menu conLrols Lhe siLe conLains will change Lheir
appearance based on Lhe skin iles and CSS iles in LhaL Lheme.
N 8y using masLer pages and Web user conLrols, you can deine a menu once and use iL on
as many pages as you like.
Creating Tree View Menus
ASP.NF1 2.0 can also display Lhe conLenLs o a siLe map as an expandable, collapsible,
indenLed lisL. Figure 2-4 provides an example. Web visiLors can use Lhe Plus (-) and Minus
(-) icons Lo expand and collapse any nodes Lhey wanL.
To view the site map, CSS proper-
ties, H^iZBVe9ViVHdjgXZ properties,
and BZcj controI properties for
the menus in this book, open the
corresponding sampIe fiIes.
@BE8 < A9 B
lf you're using Themes, you can
aIso use skins to controI the
appearance of BZcj controIs.
The tag name is <asp.Menu>.
G < C
C12622124.indd 133 9/9/05 10:01:13 AM
l34 Microsoft VisuaI web DeveIoper 2005 xpress dition. BuiId a web Site Now!
1he componenL LhaL creaLes
displays like Lhis is an ASP.NF1 2.0
IgZZK^ZlconLrol. 1he procedure
or adding a IgZZK^Zl conLrol Lo
a page is almosL Lhe same as LhaL
or adding a BZcj conLrol. 1he
dierence. ou drag a IgZZK^Zl
conLrol ouL o Lhe Loolbox raLher
Lhan dragging a BZcj conLrol.
Providing Breadcrumbs
BZcj and IgZZK^ZlXonLrols are greaL or drilling ^cid Lhe conLenL o a siLe, buL whaL abouL
WVX`igVX`^c\ or drilling dji o a siLe 1o supporL backLracking, many siLes provide WgZVY"
XgjbWh! a lisL o links LhaL leads, sLep by sLep, rom Lhe currenL page back Lo Lhe Home page.
Manually coding and updaLing breadcrumb on each page is so Ledious and-error prone
LhaL ew Web developers aLLempL iL. ForLunaLely, a new H^iZBVeEVi] conLrol included wiLh
ASP.NF1 2.0 makes Lhis Lask easy. 1his conLrol inds Lhe currenL page in your siLe map and
reads backward Lo Lhe Home page, creaLing links aL each level.
;^\jgZ&'")
41reeviewVbageb_W\fc_Tlfg[XZeTc[\VT__\fg
bY_\a^fg[TgTccXTef\ag[XVXagXebYg[\fJXU
cTZX!G[XfT`Xf\gX`TcY\_XVbageb_fg[XgeXX
i\XjTaWg[X`XahTgg[X_XYg!
C12622124.indd 134 9/9/05 10:01:14 AM
Chapter l2. Linking the Pages in Your Site AutomaticaIIy l35
ln Figure 2-5, or example, a H^iZBVeEVi] conLrol appears in Lhe Lop leL corner o Lhe
main conLenL area. 1he H^iZBVeEVi] conLrol displays Home > Online 1ricks > Disappearing
1rick based on daLa in Lhe siLe's Web.siLemap ile. 1he menu aL Lhe leL uses Lhe same siLe
map ile and Lhereore displays Lhe same links.
;^\jgZ&'"*#
4f\aZ_XSiLeMapPaLhVbageb_W\fc_Tlfg[X
UeXTWVeh`Ufg[TgTccXTe]hfgUX_bjg[X
UTaaXebYg[\fJXUcTZX!G[XSiLeMapPaLh
Vbageb_TaWg[X`XahTgg[X_XYgUbg[hfXg[X
fT`Xf\gX`TcY\_X!G[X1odaylsVbageb_Yeb`
6[TcgXe+W\fc_Tlfg[XVheeXagWTgX!
ou can add a H^iZBVeEVi]conLrol Lo any .aspx Web page, any masLer page, or any
Web user conLrol. ln Lhe 1oolbox, open Lhe NavigaLion group and Lhen drag a H^iZBVeEVi]
conLrol inLo Design view.
C12622124.indd 135 9/9/05 10:01:16 AM
l36 Microsoft VisuaI web DeveIoper 2005 xpress dition. BuiId a web Site Now!
Unlike Lhe BZcj and IgZZK^Zl conLrols, a H^iZBVeEVi] conLrol doesn'L geL iLs daLa rom
a H^iZBVe9ViVHdjgXZ. Unless your server adminisLraLor has made special arrangemenLs, a
H^iZBVeEVi] conLrol always uses Lhe deaulL siLe map ile, Web.siLemap. 1his is a good reason
noL Lo override Lhe deaulL ilename when you creaLe Lhe primary (or only) siLe map ile or
your siLe
ln Summary.
ASP.NF1 2.0 provides our server conLrols LhaL help you organize and implemenL hyperlinks
wiLhin your siLe. 1he irsL, a H^iZBVe9ViVHdjgXZ conLrol, provides access Lo a hierarchical lisL
o links you code in an XML ile named, by deaulL, web.siLemap. 1his conLrol displays noLh-
ing Lo Lhe Web visiLor, buL iL provides daLa Lo Lhe BZcj and IgZZK^Zl conLrols.
1he BZcj conLrol displays a sysLem o drop-down or ly-ouL menus based on daLa LhaL
LheH^iZBVe9ViVHdjgXZ conLrol provides. 1he IgZZK^Zl conLrol displays Lhe same daLa as a
hierarchical, expandible, and collapsible lisL o links. 1o add eiLher o Lhese conLrols Lo a Web
page, masLer page, or user conLrol, irsL add a H^iZBVe9ViVHdjgXZ conLrol, Lhen add Lhe
BZcj or IgZZK^Zl conLrol and conigure iL Lo use Lhe H^iZBVe9ViVHdjgXZ conLrol.
1he ourLh conLrol, H^iZBVeEVi], inds Lhe currenL page in Lhe siLe's web.siLemap ile,
Lhen displays each link beLween Lhe currenL page and Lhe siLe's home page. 1his provides
a breadcrumb or backLracking aciliLy.
1he nexL chapLer explains how Lo use visual Web Developer or creaLing daLabases and
connecLing Web siLes Lo Lhem.
C12622124.indd 136 9/9/05 10:01:16 AM
l37
6[TcgXe$&
6eXTg\aZTaW
6baaXVg\aZ
gb7TgTUTfXf
&(
4W`\a\fgXe\aZ7TgT
4VVXff$&+
6baaXVg\aZgbTa8k\fg\aZ
7TgTUTfX$&+
6eXTg\aZTAXj
7TgTUTfX$'%
4WW\aZTaW@bW\Yl\aZ
7TgTUTfXGTU_Xf$'&
I\Xj\aZTaWHcWTg\aZ
7TgTUTfXGTU_X
6bagXag$')
Used LogeLher, daLabases and Lhe World Wide Web exceed Lhe sum o Lheir
parLs. WiLhouL Lhis combinaLion, none o Loday's mosL popular and mosL
useul Web siLes would be possible. 1here would be no porLals, no search
engines, no e-commerce, no aucLions, no on-line banking, and no on-line
Lravel reservaLions. 1he Web would be liLLle more Lhan a pile o elecLronic
brochures.
MicrosoL

visual Web Developer" makes iL very easy Lo creaLe Web


siLes LhaL leverage Lhe power o daLabases. Working wiLh daLabases is such
a simple process LhaL in many cases you won'L need Lo wriLe a single line o
program code.
visual Web Developer includes powerul, inLegraLed, and easy-Lo-
use eaLures or working wiLh MicrosoL SOL Server", MicrosoL's premier
daLabase managemenL sysLem. 1he combinaLion o visual Web Developer
2005 Fxpress and SOL Server 2005 Fxpress is so powerul, simple, and
inexpensive LhaL MicrosoL recommends SOL Server as Lhe besL soluLion noL
only or proessional developers buL also or hobbyisLs and small Web shops.
1his is Lhe irsL o our chapLers explaining Lhe daLabase eaLures o visual
Web Developer. All our chapLers assume
you've insLalled SOL Server Fxpress on Lhe
same machine as visual Web Developer.
l you haven'L done so already, iL's Lime Lo
insLall SOL Server Fxpress.
Throughout this chapter and
the next three, unIess otherwise
stated, the term HFAHZgkZg refers
to Microsoft SOL Server 2000, SOL
Server 2005, or SOL Server 2005
xpress dition.
ABG 8
C13622124.indd 137 9/9/05 10:03:00 AM
l38 Microsoft VisuaI web DeveIoper 2005 xpress dition. BuiId a web Site Now!
Administering Data Access
$
Sa \|sJa| \eb Deve|ope ard d|sp|ay |e
Daabase |.p|oe .|rdo. Dor' bo|e
oper|rg o c|os|rg ary pa|cJ|a \eb s|e
%
|r Daabase |.p|oe. |g|c||c| |e op|eve|
rode (||ed Daa Correc|ors) ard c|oose
Add Connecton on |e s|ocJ nerJ
1o use a daLabase wiLh visual Web Developer, you musL irsL conigure a Jctc ccnnecticn
LhaL poinLs Lo Lhe speciic daLabase you wanL.
Fach daLa connecLion poinLs Lo one- and only one-daLabase. 1his isn'L a limiLaLion
because.
N ou can conigure as many daLa connecLions as you need.
N Fach Web siLe can use as many daLa connecLions as you need.
1he ocal poinL or creaLing, viewing, modiying, and deleLing daLabase connecLions is
DaLabase Fxplorer. 1his is a visual Web Developer window LhaL normally shares screen space
wiLh SoluLion Fxplorer, as shown aL Lhe leL.
1o swiLch beLween SoluLion Fxplorer and DaLabase Fxplorer, click one o Lhe Labs aL Lhe
boLLom o Lhe window. l neiLher Lhe DaLabase Fxplorer window nor Lhe DaLabase Fxplorer
Lab is visible, choose DaLabase Fxplorer rom Lhe view menu.
1he nexL secLion explains how Lo creaLe a daLa connecLion or an exisLing daLabase. 1he
secLion aLer LhaL explains how Lo creaLe boLh a new daLabase and a new daLa connecLion
LhaL poinLs Lo Lhe daLabase.
Connecting to an xisting Database
Here's Lhe procedure or connecLing Lo any Lype o daLabase LhaL your version o MicrosoL
visual SLudio

supporLs.
TO CONNCT TO A DATABAS
C13622124.indd 138 9/9/05 10:03:00 AM
Chapter l3. Creating and Connecting to Databases l39
&
| a C|oose Daa SoJce o C|arge Daa SoJce d|a|og bo. |||e |e ore s|o.r |r
||gJe 1`1 appeas. ev|e. |e er|es |r |e Daa SoJce ||s bo. ard se|ec |e
ore |a desc|bes yoJ daabase
| nJ||p|e pov|des (o d|ves) ae ava||ab|e o |e ype o daabase yoJ c|oose. |e
Daa |ov|de dopdo.r ||s .||| d|sp|ay |en |r gerea|. N|T daa pov|des ae |e
nos e||ab|e. nos secJe. ard bes peon|rg
To c|arge |e deaJ| daa pov|de o a g|ver ype o daabase. |s se|ec a daa
soJce. |er se|ec a daa pov|de. ard |ra||y se|ec |e AIways Use 1hs SeIecton
c|ec| bo.
To save yoJ c|arges ard c|ose |e C|arge Daa SoJce d|a|og bo.. c||c| |e OK bJor
'

\|er |e /dd Correc|or d|a|og bo. appeas. |rspec |e bo. ||ed Daa SoJce
Q | |e Daa SoJce bo. ees o |e ype o daabase yoJ .ar. poceed o |e re. sep
Q C|e.|se. c||c| |e C|arge bJor ard eve o sep `
T|e appeaarce o |e /dd Correc|or d|a|og bo. va|es deperd|rg or |e ype o daabase
|r a|| cases. |o.eve. |e Daa SoJce |e|d appeas |r |e sane p|ace a |e op o |e d|a|og
bo. ||gJe 1` s|o.s |o. |e /dd Correc|or d|a|og bo. |oo|s o ar e.|s|rg \|coso
SO| Seve daabase
(
Cor|gJe |e /dd Correc|or d|a|og bo. as eoJ|ed o |e ype o daabase. |er
c||c| |e OK bJor
;^\jgZ&("&
I\fhT_JXU7XiX_bcXeVTaVbaaXVggb`TalglcXfbYWTgTUTfXf!
;bjXiXe\gcebi\WXfg[X`bfgVTcTU\_\glj\g[FD?FXeiXeWTgT
UTfXf!
;^\jgZ&("'
G[\fW\T_bZUbkVbaY\ZheXfTWTgTVbaaXVg\baYeb`
I\fhT_JXU7XiX_bcXegbFD?FXeiXe!
C13622124.indd 139 9/9/05 10:03:02 AM
l40 Microsoft VisuaI web DeveIoper 2005 xpress dition. BuiId a web Site Now!
TO CONllGUk TH ADD CONNCTlON DlALOG BOX
lOk A SOL SkVk DATABAS
$
|r |e Seve Nane bo.. ere |e conpJe rane ard. | recessay. |e |rsarce rane .|ee SO|
Seve |s Jrr|rg |e daabase yoJ .ar
Noe |a c||c||rg |e Seve Nane dopdo.r ao. ||ss conpJe ranes bJ ro |rsarce ranes To
access a copy o SO| Seve |.pess Jrr|rg or a conpJe raned
S|CC|`. yoJ coJ|d se|ec |e rane S|CC|` on |e dopdo.r ||s.
bJ yoJ'd |ave o ype \Sqllxress T|e conp|ee seve rane .oJ|d
be S|CC|`\So||.pess
%
Se|ec |e ype o aJ|er|ca|or SO| Seve .||| ecogr|.e T|e
op|ors ae
Q Use windows Authentication |ses yoJ cJer \|coso
\|rdo.s

|ogor accoJr o correc|rg o SO| Seve T||s |s JsJ


a||y |e coec c|o|ce o |oca| cop|es o SO| Seve |.pess ard o J|| cop|es o SO| Seve |a Jse
\|rdo.s /J|er|ca|or
Q Use SOL Server Authentication |ses a SO| Seve Jse rane ard pass.od o correc|rg o SO|
seve | yoJ se|ec ||s op|or. yoJ nJs a|so ere |e SO| Seve Jse rane ard pass.od |a |ave
|e p|v||eges yoJ reed Typ|ca||y. a daabase adn|r|sao coro|s |ese Jseranes ard pass.ods
&

Spec|y .||c| daabase |e correc|or .||| Jse
| |e daabase |s a|eady aac|ed o SO| Seve. se|ec |e daabase on |e dopdo.r ||s ||ed Se|ec
C |re / Daabase Nane
'

| |e daabase |s |r ar nd ||e ro ye aac|ed o SO| seve
BViX]^c\9ViVWVhZ
8VeVW^a^i^ZhVcY
Hd[ilVgZKZgh^dch
All versicns cf viscl StJic.
inclJin viscl Web Develcer.
ccn ccnnect tc cnJ mcnilcte
existin SOl Server Jctcbcses.
ln cJJiticn. viscl StJic ccn
ccnnect tc cnJ mcnilcte.
N Micrcscft Access Jctcbcses.
N Dctcbcses rnnin cn
Micrcscft SOl Server 7.0
cnJ revics eJiticns.
N Orccle Jctcbcses (if bcth
Orccle cnJ Micrcscft Jctc-
bcse Jrivers cre instclleJ}.
N Anv Jctcbcse fcr which
OD3C cr Oll-D3 Jrivers
cre cvcilcble.
1here is. hcwever. c cctch.
Different versicns cf viscl
StJic rcviJe Jifferent lev-
els cf scrt fcr these cther
Jctcbcse tves. lf vc finJ thct
vcr versicn cf viscl StJic
Jcesnt scrt the fectres
vc wcnt fcr c iven Jctcbcse.
the chcices cre.
N UrcJe tc c mcre cccble
versicn cf viscl StJic.
N Ccnvert the Jctcbcse tc
SOl Server 2000 cr 200S.
An ^chiVcXZcVbZ identifies a
specific copy of SOL Server run-
ning on a computer. lf two copies
of SOL Server are running on the
same computer, they must have
different instances names such
as Xadlch and VXgdWVih, iZhi and
egdY, or k^h^WaZ and {none). SOL
Server xpress aIways runs with
the instance name Hfa:megZhh.
ABG 8
C13622124.indd 140 9/9/05 10:03:02 AM
Chapter l3. Creating and Connecting to Databases l4l
Q Spec|y |e nd ||erane |r |e /ac| / Daabase |||e e. bo. `oJ car e||e ype |e pa| ard ||e
rane yoJ .ar o c||c| |e bo.se bJor. |ocae |e ||e. ard c||c| |e Cper bJor
Q |r |e |og|ca| Nane bo.. ype a b|e rane |a desc|bes |e daabase yoJ'e aac||rg T||s rane .|||
appea |r |ae dopdo.r ||ss. ard |'s |e rane yoJ'|| Jse |r SO| saeners ard ary pogan code
yoJ .|e
(
To c|ec| yoJ .o|. c||c| |e Tes Correc|or bJor |r |e |o.e |e core o |e d|a|og bo. | yoJ
se|rgs ae coec. \|sJa| \eb Deve|ope .||| d|sp|ay 'Tes correc|or sJcceeded' | yoJ ge a d|e
er esporse. ec|ec| yoJ .o|
)

C||c| |e C| bJor o ceae |e correc|or
T|e re. correc|or s|oJ|d appea |nned|ae|y |r Daabase |.p|oe |ee ae sone .ays o see .|a |e
daabase cora|rs
Q C||c||rg |e ||Js () |cor |a pecedes |e re. daa correc|or rane s|oJ|d d|sp|ay a ||s o ob|ec
ypes |a |e daabase cora|rs ab|es. v|e.s. soed pocedJes. ard o|e ob|ec ypes
Q C||c||rg |e ||Js () |cor |a pecedes ar ob|ec ype s|oJ|d d|sp|ay a ||s o ob|ecs o |a ype |o
e.anp|e. c||c||rg |e ||Js |cor () |a pecedes Tab|es .||| d|sp|ay a ||s o ab|es
Q C||c||rg |e ||Js () |cor |a pecedes a ab|e s|oJ|d d|sp|ay a ||s o |e|ds ard so o|
| yoJ a|| o ge |ese esJ|s. yoJ daabase o yoJ daabase correc|or ae pobab|y |rcoec
C13622124.indd 141 9/9/05 10:03:03 AM
l42 Microsoft VisuaI web DeveIoper 2005 xpress dition. BuiId a web Site Now!
Creating a New Database
Physically, SOL Server daLabases reside in Lwo iles. a main ile wiLh a ilename, exLension o
.md and a log ile wiLh an exLension o .ld. 1hese iles can reside anywhere on Lhe compuLer
where SOL Server is running, buL Lhe ollowing locaLions are cusLomary.
N For daLabases LhaL only one ASP.NF1 2.0 Web siLe will use, Lhe mosL convenienL locaLion
is LhaL Web siLe's App_DaLa older. 1his greaLly simpliies publishing Lhe daLabase and
geLLing iL Lo work on Lhe remoLe siLe.
N For daLabases LhaL mulLiple applicaLions or Web siLes will use, Lhe besL locaLion is usually
Lhe SOL Server deaulL DaLa older. 1his usually resembles
C.\Program Files\MicrosoL SOL Server\MSSOL.\MSSOL\DaLa
Regardless o locaLion, you can creaLe new SOL Server daLabases direcLly in visual
Web Developer. 1he resL o Lhis book, or example, will use a SOL Server daLabase named
ConLosoMagic.md LhaL resides in Lhe sample Web siLe's App_DaLa older.
TO CkAT TH SOL SkVk DATABAS lOk TH SAMPL SlT
$

Cper |e \eb s|e |r \|sJa| \eb Deve|ope
%

C|oose New fIe on |e |||e nerJ
&
\|er |e /dd Ne. |en d|a|og bo. appeas.
se|ec SOL Database |r |e Tenp|aes bo.
'

|r |e Nane bo.. ype ContosoMagc.mdf
(
C||c| |e Add bJor | ar ponp |||e |e o|
|o.|rg appeas. c||c| |e Yes bJor \|sJa|
\eb Deve|ope .||| ceae |e daabase ard |e
daa correc|or
C13622124.indd 142 9/9/05 10:03:03 AM
Chapter l3. Creating and Connecting to Databases l43
TO CkAT A DATABAS THAT kSlDS lN
SOL SkVk'S DlAULT DATA lOLDk
$
|r Daabase |.p|oe. |g|c||c| |e op|eve| rode (||ed Daa Correc|ors) ard c|oose
Create New SOL Server Database on |e s|ocJ nerJ
%
\|er |e Ceae Ne. SO| Seve Daabase d|a|og bo. s|o.r |r ||gJe 1`` appeas. spec|y
|e daabase seve rane |Js as yoJ d|d .|er correc|rg o ar e.|s|rg daabase |r |e pe
v|oJs sec|or |. o e.anp|e. yoJ'e Jrr|rg SO| Seve |.pess or a conpJe raned N|C|||\.
spec|y N|C|||\\So||.pess
&
|r |e |og Cr To T|e Seve ane. spec|y yoJ ceder|a|s o cea|rg |e daabase |o SO|
Seve |.pess. ||s |s JsJa||y \|rdo.s aJ|er|ca|or
'

|r |e Ne. Daabase Nane bo.. ype a b|e rane |a desc|bes |e daabase yoJ'e cea|rg
(
C||c| |e OK bJor o ceae |e daabase |o yoJ corver|erce. \|sJa| \eb Deve|ope .|||
|nned|ae|y ceae a daa correc|or as .e||
Adding and Modifying Database TabIes
visual Web Developer can direcLly creaLe, modiy, and deleLe Lables in SOL Server daLabases.
For example, Lo creaLe a ProducLs Lable in Lhe ConLosoMagic daLabase, proceed as ollows.
TO CkAT A PkODUCTS TABL lN TH CONTOSOMAGlC DATABAS
$
|r |e Daabase |.p|oe .|rdo.. c||c| |e PIus (+) |cor re. o |e Coroso\ag|c daa correc|or
yoJ ceaed |r |e pev|oJs sec|or T|er. |g|c||c| |e 1abIes ery ard se|ec Add New 1abIe on
|e s|ocJ nerJ
;^\jgZ&("(
G[\fW\T_bZUbkVeXTgXfTaXjFD?FXeiXeWTgT
UTfXTaWTaXjWTgTVbaaXVg\bagb`TgV[!<g
WbXfag[bjXiXeVeXTgXTalgTU_Xf!
C13622124.indd 143 9/9/05 10:03:04 AM
l44 Microsoft VisuaI web DeveIoper 2005 xpress dition. BuiId a web Site Now!
%
\|sJa| \eb Deve|ope .||| d|sp|ay a Tab|e Des|gre o ran|rg ard desc|b|rg |e |e|ds |r yoJ re.
ab|e To ceae |e |s |e|d. poceed as o||o.s
a. Se |e |rse|or po|r |r |e |s o. o |e Tab|e Des|gre. Jrde |e Co|Jnr Nane |e|d
b. |re |e rane PrcJctlJ ard pess |e Tab |ey
c. |r |e Daa Type co|Jnr. se|ec |r on |e dopdo.r ||s ard pess |e Tab |ey
d. C|ea |e c|ec| bo. |r |e /||o. NJ||s co|Jnr
e. |r |e Co|Jnr |ope|es ab rea |e boon o |e .|rdo.. sco|| do.r o |der|y Spec||ca|or. c||c|
|e ||Js () |cor o e.pard |. ard se |e (|s |der|y) popey o `es ||gJe 1`4 s|o.s ||s sep |r
pogess
f. ||g|c||c| ary.|ee |r |e re. PrcJctlJ o. ard se|ec Se ||nay |ey on |e s|ocJ nerJ
;^\jgZ&(")
I\fhT_JXU7XiX_bcXe\aV_hWXfTGTU_X
7Xf\ZaXeg[TgVTaTWW`bW\YlTaW
WX_XgXY\X_Wf\aTWTgTUTfXgTU_X!
C13622124.indd 144 9/9/05 10:03:05 AM
Chapter l3. Creating and Connecting to Databases l45
Se|rg |e (ls ldenLiLy) properLy o `es e||s SO| Seve |a evey |ne | adds a ecod o |e ab|e. |
s|oJ|d se |e g|ver |e|d o a Jr|oJe va|Je Se|ec|rg ore o noe |e|ds. |g|c||c||rg |e se|ec|or. ard
|er c|oos|rg Se ||nay |ey on |e s|ocJ nerJ e||s SO| Seve o ea |ose |e|ds as |e Je
|der|y o eac| ecod
&
|ac| |ne yoJ ceae a |e|d by ||||rg |r |e b|ar| o. a |e boon o |e g|d. \|sJa| \eb
Deve|ope ceaes a re. b|ar| o. so yoJ car apperd aro|e |e|d |o||o.|rg ||s paer. se |e
|rse|or po|r |r |e secord. ||d. ard oJ| g|d o.s ard ass|gr |e coespord|rg |e|d pope|es on
Tab|e 1`1
'
C|oose Save 1abIec on |e |||e nerJ. .|ee n |s a seoJer|a| rJnbe |a \|sJa| \eb Deve|ope
.||| ass|gr \|er |e C|oose Nane d|a|og bo. s|o.r be|o. appeas. ere PrcJcts ard |er c||c|
|e OK bJor
'
C|oose Save 1abIec on |e |||e nerJ. .|ee n |s a seoJer|a| rJnbe |a \|sJa| \eb Deve|ope
.||| ass|gr \|er |e C|oose Nane d|a|og bo. s|o.r be|o. appeas. ere EgdYjXih ard |er c||c|
|e OK bJor
1o add, modiy, or deleLe ields in an exisLing Lable, righL-click Lhe Lable in DaLabase
Fxplorer and Lhen choose Open 1able DeiniLion. 1his will display Lhe grid shown in
Figure 8-4.
1o deleLe a Lable, righL-click iL in DaLabase Fxplorer and choose DeleLe. 1his deleLes boLh
Lhe Lable deiniLion and any daLa Lhe Lable mighL conLain.
IVWaZ&("&
9\X_Wf\ag[X6bagbfb@TZ\VCebWhVgf
GTU_X
CoIumn Name DataType AIIow NuIIs ldentity Primary Key
PrcJctlJ inL Cleared es es
CctecrvlJ inL Cleared (deaulL) (deaulL)
PrcJctNcme varchar(255) Cleared (deaulL) (deaulL)
PrcJctPrice money Cleared (deaulL) (deaulL)
C13622124.indd 145 9/9/05 10:03:06 AM
l46 Microsoft VisuaI web DeveIoper 2005 xpress dition. BuiId a web Site Now!
Viewing and Updating Database TabIe Content
1o view Lhe daLa in any Lable, righL-click Lhe Lable name in DaLabase Fxplorer and choose
Show 1able DaLa. 1his sLarLs a parL o visual Web Developer called Lhe Ouery Developer LhaL
queries and displays Lhe daLa in LhaL Lable. As shown in Figure 8-5, Lhe Ouery Designer
window conLains up Lo our panes.
lniLially, Ouery Designer runs a very simple query and displays Lhe resulLs in Lhe ResulLs
pane. 1his is a very simple view LhaL looks somewhaL like a spreadsheeL. ou can use Lhis
view Lo change, add, or deleLe records.
;^\jgZ&("*
<a\g\T__lg[XDhXel7Xf\ZaXeW\fc_Tlf
ba_lg[XEXfh_gfcTaXg[TgTccXTef
[XeXTgg[XUbggb`!G[Xgbcg[eXX
cTaXfZeTc[\VT__lVbaY\ZheX`beX
TWiTaVXWdhXe\Xf!
D|agan |are
C|e|a |are
SO| |are
|esJ|s |are
C13622124.indd 146 9/9/05 10:03:07 AM
Chapter l3. Creating and Connecting to Databases l47
N 1o change Lhe value o any ield, selecL iL and Lype Lhe new value.
N 1o add a record, Lype iLs daLa values inLo Lhe blank row aL Lhe end o Lhe Lable.
N 1o deleLe a record, selecL iL and Lhen press Lhe Del key.
visual Web Developer immediaLely inserLs, updaLes, or deleLes Lhe currenL record
whenever you press FnLer, press Del, or move Lo anoLher record. 1here's no need Lo save
anyLhing beore you close Lhe view.
l you simply wanL a quick look aL your daLa, perhaps Lo make a ew correcLions, Lhe
ResulLs pane may be all you need. l, however, you wanL Lo perorm more complex queries
or jusL wanL more conLrol, Lhe oLher Lhree panes can be very useul. 1o display any o Lhese
panes.
l. RighL-click Lhe Ouery Designer window.
2. Choose Pane rom Lhe shorLcuL menu.
3. SelecL Lhe pane you wanL Lo display or hide.
Here's a brie descripLion o each pane and some reasons you mighL wanL Lo use iL.
N DiagramDisplays a small window or each Lable involved in Lhe query. Check boxes
indicaLe ields desLined or ouLpuL, and AZ icons indicaLe ordering in ascending or
descending sequence.
N 1o add a Lable Lo Lhe diagram (and hence Lo Lhe query) drag iL rom DaLabase
Fxplorer and drop iL in Lhe Diagram pane.
N 1o jcin any pair o Lables (LhaL is, Lo ind maLching records based on daLa values) drag
Lhe ield you wanL Lo maLch rom one Lable and drop iL on Lhe ield you wanL Lo
maLch in Lhe oLher Lable.
N 1o modiy Lhe join properLies, righL-click Lhe line connecLing Lhe Lwo Lables and
choose Lhe Lype o join you wanL.
N Criteria Displays a Labular, ediLable view o Lhe ields and Lables involved in Lhe query.
N SOL DispIays Lhe SOL sLaLemenL LhaL generaLes Lhe query.
C13622124.indd 147 9/9/05 10:03:07 AM
l48 Microsoft VisuaI web DeveIoper 2005 xpress dition. BuiId a web Site Now!
Whenever you updaLe Lhe Diagram, CriLeria, or SOL pane, visual Web Developer will
updaLe Lhe oLher Lwo panes. l, or example, you modiy Lhe SOL pane, visual Web
Developer will updaLe Lhe Diagram and CriLeria panes accordingly.
N kesuIts Displays Lhe resulLs o running Lhe query. 1he deaulL query LhaL appears when
you irsL choose Lhe Show 1able DaLa command is.
5LLLC1 " IROM <fab]e-name>
where <Lable-name> is Lhe name o your Lable.
l you use Lhe Diagram, CriLeria, or SOL pane Lo change Lhis query, Lhe ResulLs pane
won'L show Lhe eecLs unLil you eiLher.
N Choose FxecuLe SOL rom Lhe Ouery Designer menu, or
N RighL-click Lhe Ouery Designer window and choose FxecuLe SOL rom Lhe shorLcuL menu.
ln Summary.
visual Web Developer can connecL your Web siLe Lo as many exisLing daLabases as you like.
lL can also creaLe daLabases and connecL Lo Lhem in one operaLion. 1hese daLabases Lypically
reside in your Web siLe's App_DaLa older or in SOL Server's deaulL DaLa older.
visual Web Developer can also creaLe, modiy, and updaLe daLabase Lables and records,
all wiLhouL orcing you Lo leave Lhe program.
1he nexL chapLer will explain how Lo creaLe a simple Web page LhaL updaLes Lhe
ProducLs Lable you creaLed in Lhis chapLer.
C13622124.indd 148 9/9/05 10:03:08 AM
&).
6[TcgXe$'
7\fc_Tl\aZ
7TgTUTfX
<aYbe`Tg\ba
&)
Hf\aZ7TgTFbheVXf$(#
6baY\Zhe\aZ7TgT
FbheVXf$($
7\fc_Tl\aZ7TgTUTfX
<aYbe`Tg\ba$((
6baY\Zhe\aZT:e\WI\Xj
6bageb_$(*
DaLabase programming has a repuLaLion or being a diiculL Lask, and wiLh
good reason. DaLabases are boLh complex and mission-criLical. DaLabases
are also so imporLanL and so useul, however, LhaL soLware makers are con-
Linually sLriving Lo provide inLuiLive and easy-Lo-use daLabase Lools.
MicrosoL

ASP.NF1 2.0 and MicrosoL visual Web Developer" provide


some o Lhe besL and mosL user-riendly Lools yeL.
WiLh visual Web Developer, you can creaLe simple- Lo moderaLely-
complex Web daLabase applicaLions using only Lhe graphical design
inLerace. 1his involves Lhree kinds o componenLs.
N 9ViV8dccZXi^dch Provide paLhways Lo daLabases. ChapLer 8 explained
how Lo creaLe and modiy Lhese paLhways.
N 9ViVHdjgXZh Work Lhrough daLa connecLions Lo reLrieve, inserL, updaLe,
and deleLe daLabase records, buL display noLhing Lo Lhe Web visiLor.
N 9ViV"7djcY8dcigdah ReLrieve and display inormaLion rom a daLa
source. ln Lhe case o inserL, updaLe, and deleLe operaLions, daLa-bound
conLrols also supply Lhe daLa source wiLh inormaLion or processing.
1his chapLer explains how Lo use and creaLe daLa sources and how Lo use
daLa-bound conLrols or displaying daLa. ChapLer 5 will explain how Lo use
Lhese conLrols or making daLabase changes.
C14622124.indd 149 9/9/05 10:05:28 AM
&*% B^Xgdhd[iK^hjVaLZW9ZkZadeZg'%%*:megZhh:Y^i^dc/7j^aYVLZWH^iZCdl
Jh^c\9ViVHdjgXZh
;^\jgZ&)"&
7eTZZ\aZTgTU_XbedhXelYeb`7TgTUTfX
8kc_beXegbTabcXaJXUcTZXVeXTgXf
gjbVbageb_f-TWTgTfbheVXVbageb_TaW
TC|d\|e.Vbageb_!<gT_fbW\fc_Tlfg[X
C|d\|e.Vbageb_fgTf^`Xah!
1o appreciaLe Lhe power o daLa sources and daLa-bound conLrols, Lry Lhis simple procedure.
&# ln DaLabase Fxplorer, expand any exisLing daLa connecLion and locaLe a Lable or query
you'd like Lo display in a Web page.
'# Open Lhe Web page in Design view.
(# Drag Lhe Lable or query ouL o DaLabase Fxplorer and drop iL onLo Lhe open page.
As shown in Figure 4-, Lhis adds Lwo conLrols Lo Lhe Web page. a daLa source conLrol
(in Lhis case, a SqlDctcScrce conLrol named SqlDctcScrce1) and a CriJview conLrol (which
displays Lhe Labular grid wiLh Lhe daLabase ields as column headings.) 1he CriJview is one
o Lhe mosL popular and mosL
useul daLa-bound conLrols. visual
Web Developer auLomaLically
binJs (LhaL is, connecLs) Lhe new
CriJview Lo Lhe new daLa source.
ou can also creaLe a daLa
source by dragging an icon ouL
o Lhe 1oolbox's DaLa group and
dropping iL onLo your page. 1able
4- describes some o Lhe mosL
popular daLa source conLrols. 1he
1oolbox in your copy o visual
Web Developer mighL oer more
or ewer daLa source conLrols,
depending on iLs version and on
oLher soLware you've insLalled.
C14622124.indd 150 9/9/05 10:05:29 AM
8]VeiZg&)/9^heaVn^c\9ViVWVhZ>c[dgbVi^dc &*&
8dc[^\jg^c\9ViVHdjgXZh
When you creaLe a daLa source by dragging a Lable or query rom DaLabase Fxplorer, iL
delivers all Lhe records and all Lhe ields in LhaL Lable or query, wiLhouL sorLing. 1o change
Lhese deaulLs or Lo conigure a daLa source you creaLed rom Lhe 1oolbox, proceed as
ollows.
ID8DC;><JG:696I6HDJG8:
IVWaZ&)"&
6b``ba4FC!A8G%!#7TgTFbheVX
6bageb_f
$
Se|ec |e daa soJce coro|. c||c| |s sna
ag |cor. ard se|ec 7cbZ][ifY8UhUGcifWY
on |e esJ||rg as| nerJ
%
\|er |e C|oose `oJ Daa Correc|or d|a
|og bo. s|o.r |r ||gJe 14 appeas. e||e
Q |se |e dopdo.r bo. o se|ec |e daa cor
rec|or yoJ .ar. o
Q C||c| |e Ne. Correc|or bJor o ceae a re.
daa correc|or T||s d|sp|ays |e /dd
Correc|or d|a|og bo. |a C|ape 1` e.p|a|red
8dcigda 9ZhXg^ei^dc
SqlDctcScrce ReLrieves and updaLes inormaLion in MicrosoL SOL Server"
daLabases.
AccessDctcScrce ReLrieves and updaLes inormaLion in MicrosoL Access daLabases.
ObjectDctcScrce ReLrieves and updaLes inormaLion Lhrough a cusLom objecL. ln an
applicaLion wiLh Lhree Liers (presenLaLion, business logic, and daLa
access) Lhe bound conLrol would Lypically be in Lhe presenLaLion
Lier and Lhe cusLom objecL would be in Lhe business logic Lier.
XmlDctcScrce ReLrieves and opLionally Lransorms inormaLion in XML iles.
SiteMcDctcScrce ReLrieves inormaLion rom an XML siLe map ile. ChapLer 2
explained how Lo use a siLe map ile and a SiteMcDctcScrce
conLrol Lo display hyperlinks in Men. 1reeview. and SiteMcPcth
conLrols.
C14622124.indd 151 9/9/05 10:05:30 AM
&*' B^Xgdhd[iK^hjVaLZW9ZkZadeZg'%%*:megZhh:Y^i^dc/7j^aYVLZWH^iZCdl
To d|sp|ay |e correc|or s|rg |e daa soJce .||| Jse. c||c| |e ||Js () |cor |a pecedes |e
Correc|or S|rg se|rg
;^\jgZ&)"'
G[XY\efgfgXc\aVbaY\Zhe\aZTWTgT
fbheVX\fgbfcXV\Ylg[XWTgTVbaaXV
g\ba\gf[bh_WhfX!
&
C||c| |e BYlh bJor o d|sp|ay |e Cor|gJe T|e Se|ec Saener d|a|og bo. s|o.r |r ||gJe 14`
|o s|np|e oJe|es. se|ec GdYW]Zm7c`iabg:fca5HUV`YCfJ]Yk ard cor|gJe |ese se|rgs
Q CVbZSe|ec |e ab|e o oJey yoJ .ar T|e dopdo.r c|o|ces .||| a|| cone on |e daa correc
|or yoJ spec||ed or |e |s page o |e .|.ad
Q 8dajbchSe|ec |e c|ec| bo. |a pecedes eac| |e|d yoJ .ar |e daa soJce o e|eve o Jpdae
To spec|y a|| |e |e|ds. se|ec |e ase|s| () c|ec| bo.
Q GZijgcDcanJc^fjZGdlh Se|ec ||s c|ec| bo. |. .|er .o o noe ecods |ave |der|ca| daa va|
Jes. yoJ or|y .ar o e|eve ore o |en
C14622124.indd 152 9/9/05 10:05:30 AM
8]VeiZg&)/9^heaVn^c\9ViVWVhZ>c[dgbVi^dc &*(
Q L=:G: C||c| ||s bJor o d|sp|ay ar /dd \|||| C|aJse d|a|og bo. T||s pov|des a nears o eJr
or|y |ose ecods |av|rg cea|r daa va|Jes |o e.anp|e. yoJ car spec|y |a |e va|Je o a g|ver |e|d
nJs nac| |e va|Je o a corsar. aro|e coro| or |e \eb page. a coo||e. a corver|ora| |T\|
on |e|d. ar /S|N|T po||e |e|d. a oJey s|rg va|ab|e. o a sess|or va|ab|e
Q DG9:G7N C||c| ||s bJor o d|sp|ay ar /dd C|D|| |` C|aJse d|a|og bo. .|ee yoJ car spec|y ore.
.o. o |ee |e|ds o Jse |r so|rg |e daa
Q 6YkVcXZY C||c| ||s bJor o d|sp|ay ar /dvarced SO| Cerea|or Cp|ors d|a|og bo. | yoJ p|ar o
Jse |e daa soJce o Jpda|rg. se|ec |e c|ec| bo. ||ed Cereae |NS||T. ||D/T|. /rd D|||T|
Saeners T|e o|e op|or or ||s d|a|og bo.. |se Cp|n|s|c CorcJercy. |s a Jr|rg aco yoJ n|g|
reed o ad|Js |r vey bJsy erv|orners
| |ese op|ors dor' pov|de |e |e.|b|||y yoJ reed. |groe |en ard se|ec GdYW]Zm57ighcaGE@
GhUhYaYbhCfGhcfYXDfcWYXifY rea |e op o |e d|a|og bo.
;^\jgZ&)"(
G[\fj\mTeWcTZXfcXV\Y\Xfj[\V[
Y\X_WfTaWeXVbeWfg[XWTgTfbheVX
f[bh_Wcebi\WXTaW\aj[TgbeWXe!
C14622124.indd 153 9/9/05 10:05:31 AM
&*) B^Xgdhd[iK^hjVaLZW9ZkZadeZg'%%*:megZhh:Y^i^dc/7j^aYVLZWH^iZCdl
To spec|y a cJson S|||CT. ||D/T|. |NS||T. o D|||T| saener. se|ec |e coespord|rg ab ard |er
c||c| |e EiYfm6i]`XYf bJor T||s d|sp|ays |e sane oJey des|gre |a C|ape 1` desc|bed |r |e
sec|or ||ed viewin cnJ UJctin Dctcbcse 1cble Ccntents Deve|op yoJ SO| saener. es | by
c||c||rg |e 9lYWihYEiYfm bJor. |er c||c| |e C? bJor
(
C||c||rg |e BYlh bJor d|sp|ays |e |as page |r |e .|.ad. |e Tes OJey d|a|og bo. s|o.r |r
||gJe 14' C||c| |e HYghEiYfm bJor ard ve|y |a |e cera| bo. d|sp|ays |e daa yoJ .ar
| |'s coec. c||c| |e :]b]g\ bJor | ro. c||c| |e DfYj]cig bJor ard nod|y yoJ er|es
;^\jgZ&)")
<YlbhV[bbfXgbhfXTVhfgb`FD?
fgTgX`XagbefgbeXWcebVXWheXg[X
j\mTeWW\fc_Tlfg[\fcTZXfblbh
VTafhcc_lg[bfXfgTgX`Xagf!
'
| yoJ se|eced Spec|y / CJson SO| Saener C Soed |ocedJe |r |e pev|oJs sep. c||c||rg |e
BYlh bJor .||| d|sp|ay |e De|re CJson Saeners C Soed |ocedJes d|a|og bo. s|o.r |r
||gJe 144
C14622124.indd 154 9/9/05 10:05:32 AM
8]VeiZg&)/9^heaVn^c\9ViVWVhZ>c[dgbVi^dc &**
NoLe LhaL each daLa source conLrol sLores only one coniguraLion. LhaL is, one Lable or
query, one selecLion o ields, one sorL order, and so orLh. l your page needs Lo access Lwo
or more Lables-or Lhe same Lable or query wiLh dierenL criLeria-you'll need Lo add and
conigure a separaLe daLa source conLrol or each one.
9^heaVn^c\9ViVWVhZ>c[dgbVi^dc
Many ASP.NF1 2.0 Web server conLrols can bind Lo a daLa source. For example, Lo ill a drop-
down lisL wiLh choices rom a daLabase Lable, seL Lhese Lhree properLies on any
DrcDcwnlist conLrol.
N 9ViVHdjgXZ>9 1he name o a daLa source conLrol LhaL poinLs Lo Lhe Lable or query LhaL
provides Lhe daLa.
;^\jgZ&)"*
J[XalbhV_\V^g[XGXfgDhXelUhg
gba\ag[\fW\T_bZUbkg[Xj\mTeW
W\fc_TlfTceXi\XjbYj[Tgg[XWTgT
fbheVXj\__WX_\iXe!
C14622124.indd 155 9/9/05 10:05:33 AM
&*+ B^Xgdhd[iK^hjVaLZW9ZkZadeZg'%%*:megZhh:Y^i^dc/7j^aYVLZWH^iZCdl
N 9ViVIZmi;^ZaY 1he name o Lhe ield LhaL provides Lhe values Lhe Web visiLor will see.
1his is usually a LexL ield such as PrcJctNcme or CctecrvNcme.
N 9ViVKVajZ;^ZaY 1he name o Lhe ield LhaL provides Lhe values Lhe Web page will sub-
miL. 1his is oLen a code ield such as PrcJctlJ or CctecrvlJ.
ln many case, however, developers wanL Lo display mulLiple ields or even mulLiple
records in a single conLrol, and perhaps supporL daLabase updaLing as well. 1o handle such
requiremenLs, ASP.NF1 2.0 provides Lhe conLrols lisLed in 1able 4-2.
IVWaZ&)"'
5bhaW7TgT7\fc_Tl6bageb_f
O Lhese ive conLrols, Lhe CriJview. Detcilsview. and lcrmview are Lhe newesL, Lhe
easiesL Lo use, and Lhereore Lhe mosL inLeresLing. 1he coniguraLion process is essenLially Lhe
same or each o Lhem.
1he remainder o Lhis chapLer will explain how Lo conigure a CriJview conLrol Lo display
producLs or Lhe ConLoso Magic siLe. 1he nexL chapLer, which explains updaLing, has an
example LhaL uses Lhe Detcilsview conLrol.
8dcigda 9ZhXg^ei^dc Hjeedgih >cigdYjXZY
JeYVi^c\ ^c6HE#C:I
CriJview Displays mulLiple records in a row and UpdaLe, DeleLe 2.0
column ormaL.
Detcilsview Displays one record aL a Lime using lnserL, UpdaLe, 2.0
simple H1ML. DeleLe
lcrmview Displays one record aL a Lime in a highly lnserL, UpdaLe, 2.0
ormaLLed orm. DeleLe
Dctclist RepeaLs a cusLom-designed LemplaLe once CusLom .0
or each record in a daLa source, merging Programming
values rom Lhe currenL record.
Reecter Similar Lo Lhe Dctclist, buL supplies no CusLom .0
H1ML o iLs own. 1his improves lexibiliLy Programming
buL requires more complex LemplaLes.
C14622124.indd 156 9/9/05 10:05:33 AM
8]VeiZg&)/9^heaVn^c\9ViVWVhZ>c[dgbVi^dc &*,
8dc[^\jg^c\V<g^YK^Zl8dcigda
1his secLion explains how Lo creaLe Lhe ConLoso Magic CosLumes page shown in Figure 4-6.
1he banner, menu, ooLer, and breadcrumb areas should be amiliar, as should Lhe Lheme,
Lhey all come rom earlier chapLers in Lhis book.
;^\jgZ&)"+
4C|d\|e.Vbageb_VeXTgXWg[XWTgTW\fc_Tl\a
g[XVXagXebYg[\fJXUcTZX!
NoLe Lhe grid displaying Lhe irsL 0 producLs in Lhe CosLumes caLegory. 1his is a
CriJview conLrol displaying inormaLion rom Lhe ProducLs Lable you creaLed in ChapLer 8.
C14622124.indd 157 9/9/05 10:05:35 AM
&*- B^Xgdhd[iK^hjVaLZW9ZkZadeZg'%%*:megZhh:Y^i^dc/7j^aYVLZWH^iZCdl
ID8G:6I:6<G>9K>:LL:7E6<:
$

Cper a re. b|ar| page. app|y|rg ary nase pages o o|e ona|rg yoJ .ar
%

/dd a CriJview coro| ard a SqlDctcScrce coro| o |e page |||e
Q Dag |e PrcJcts ab|e on Daabase |.p|oe ard dop | oro yoJ page
Q Dag a CriJview coro| ard a SqlDctcScrce coro| on |e Daa goJp |r |e Too|bo.. dopp|rg
bo| oro |e oper \eb page
& D|sp|ay |e SqlDctcScrce coro|'s as| nerJ ard c||c| 7cbZ][ifY8UhUGcifWY!
'
\|er |e C|oose `oJ Daa Correc|or d|a|og bo. appeas. se|ec o ceae a correc|or o |e
Coroso\ag|c daabase ard |er c||c| |e Ne. bJor
(
\|er |e Cor|gJe T|e Se|ec Saener d|a|og bo. appeas. se|ec |e |odJcs ab|e ard or|y
|e PrcJctlJ. PrcJctNcme. ard PrcJctPrice |e|ds
)
C||c| |e \|||| bJor ard |er. .|er |e /dd \|||| C|aJse d|a|og bo. appeas. spec|y
|ese va|Jes
Q 8dajbc Caegoy|d
Q DeZgVidg ~ (eoJa|s)
Q HdjgXZ Nore
Q KVajZ 1 (Noe T||s se|rg |s |r |e |aanee |ope|es ane)
ard |er c||c| |e 5XX bJor T||s ||n|s |e oJey so |a | or|y eJrs ecods |av|rg a CctecrvlJ
rJnbe o 1 ||gJe 14 |||Jsaes ||s cor|gJa|or
C14622124.indd 158 9/9/05 10:05:35 AM
8]VeiZg&)/9^heaVn^c\9ViVWVhZ>c[dgbVi^dc &*.
*
C||c| |e C? bJor o c|ose |e /dd \|||| C|aJse d|a|og bo.. |er c||c| |e CfXYf6m bJor |r |e
Cor|gJe T|e Se|ec Saener d|a|og bo.
+
\|er |e /dd C|D|| |` C|aJse d|a|og bo. appeas. se So |y o PrcJctNcme ard |er c||c| |e
C? bJor T||s esab||s|es |e deaJ| so ode o yoJ d|sp|ay
,

C||c| |e BYlh bJor. |e HYghEiYfm bJor. ard |e :]b]g\ bJor o conp|ee |e .|.ad
Coniguring Lhe CriJview conLrol is a separaLe operaLion. 1o compleLe Lhis Lask, proceed
as ollows.
ID8DC;><JG:I=:<G>9K>:L8DCIGDA
$
D|sp|ay |e C|d\|e. coro|'s as| nerJ ard na|e sJe |e C|oose Daa SoJce dopdo.r ||s
po|rs o |e daa soJce yoJ |Js cor|gJed
;^\jgZ&)",
G[\fW\T_bZUbkVbaY\ZheXfg[XY\_gXefXg
g\aZfYbeTWTgTfbheVX!7bagYbeZXggb
V_\V^g[X4WWUhggbaUXYbeXV_\V^\aZg[X
B>Uhggba!
C14622124.indd 159 9/9/05 10:05:36 AM
&+% B^Xgdhd[iK^hjVaLZW9ZkZadeZg'%%*:megZhh:Y^i^dc/7j^aYVLZWH^iZCdl
%

Se|ec |e o||o.|rg c|ec|bo.es
Q :cVWaZEV\^c\ D|sp|ays or|y a se rJnbe o ecods a a |ne To nove be.eer ses. |e \eb v|s|o
c||c|s a rJnbe a |e boon o |e d|sp|ay T|e d|sp|ay |r ||gJe 14b |as .o ses o ecods. rJnbeed
1 ard
Q :cVWaZHdgi^c\ /||o.s s|e v|s|os o so |e d|sp|ay or ary co|Jnr by c||c||rg |s |ead|rg |r
||gJe 14b. |e v|s|o |s aboJ o so |e d|sp|ay or |odJc ||ce
&
C||c| 9X]h7c`iabg |r |e as| nerJ ard |er. .|er |e ||e|ds d|a|og bo. s|o.r |r ||gJe 148
appeas. Jse |e Se|eced ||e|ds bo. ard |s acconpary|rg Jpao. ard do.rao. bJors o
aarge |e oJpJ |e|ds |r ||s ode CebWhVgAT`X. CebWhVg<W. CebWhVgCe\VX
;^\jgZ&)"-
J\g[g[\fW\T_bZUbklbhVbaY\ZheX
j[\V[Y\X_WfTC|d\|e.Dea||s\|e.be
|on\|e.Vbageb_j\__W\fc_TlTaWT_fb
[bjg[XY\X_Wfj\__TccXTe!
'
Se|ec CebWhVgAT`X |r |e Se|eced ||e|ds bo.. ard |er Jse |e |oJrd||e|d |ope|es bo. o app|y
|e pope|es ||sed |r Tab|e 14` |epea ||s pocedJe o |e CebWhVg<W. ard CebWhVgCe\VX |e|ds
C14622124.indd 160 9/9/05 10:05:37 AM
8]VeiZg&)/9^heaVn^c\9ViVWVhZ>c[dgbVi^dc &+&
(
C||c| |e C? bJor o c|ose |e ||e|ds d|a|og bo.. |er se|ec |e :e\WI\Xj ard Jse \|sJa| \eb
Deve|ope's rona| |ope|es .|rdo. o cor|gJe |e o||o.|rg se|rgs |o| o |ese se|rgs ae
er|e|y cosne|c
Q 8hh8aVhh fcrmbcx (T||s |s |e rane o a CSS sy|e J|e)
Q =dg^odciVa6a^\c Cere
)
Save |e page. |er d|sp|ay | |r yoJ bo.se Tes ard e|re |e page. | des|ed
1he sample ConLoso Magic siLe has a separaLe page or each o Lhe 0 caLegories. One
is Lhe CosLumes page, Lhe oLher nine are direcL copies wiLh only Lhe page LiLle and selecLion
criLeria changed. 1his provides enough pages Lo make Lhe menu example somewhaL realisLic.
ln a real siLe, you mighL preer a single producLs page wiLh a drop-down lisL Lo selecL
Lhe caLegory. 1he ConjureCaLs.aspx page in Lhe sample iles provides an example o Lhis
Lechnique. 1his page diers rom Lhe CosLumes page in LhaL.
N lL conLains Lwo SqlDctcScrce conLrols. one or Lhe ProducLs Lable and one or a
CaLegories Lable.
N lL conLains a DrcDcwnlist conLrol conigured as Lhe earlier secLion LiLled, "Displaying
DaLabase lnormaLion," explained.
ln addiLion, Lhis conLrol's AtcPcst3ccl properLy is seL Lo 1rue so LhaL changing Lhe
selecLion auLomaLically submiLs Lhe orm and reLrieves a lisL o producLs in Lhe newly-
selecLed caLegory.
IVWaZ&)"(
5bhaW9\X_WCebcXeg\XfYbeg[X
6bfgh`Xf!TfckCTZX
EgdeZgin 9ViV;^ZaY
DctclielJ PrcJctNcme PrcJctlJ PrcJctPrice
DctclcrmctStrin [0.S#,##0.00}
HecJer1ext ProducL Name ProducL ld ProducL Price
HtmllnccJe 1rue 1rue False
ltem Stvle. HcrizcntclAlin RighL RighL
ltem.Stvle verticclAlin 1op 1op 1op
6HE#C:I9ViV;dgbVi
Hig^c\h
1he Ccntcsc Mcic
Ccstmes ce in this secticn
ses the Jctc fcrmct strin
{0.$=.==0.00} tc Jislcv rices.
1his is c tviccl ASP.Nl1 fcr-
mcttin strin.
N A cir cf crlv brcces ({ }}
cre reqireJ Jelimiters.
N 1he cclcn (.} secrctes
the fielJ nmber frcm the
fcrmct secificcticn.
N 1he fielJ nmber will
clwcvs be 0. inJicctin
fielJ nmber cne.
N $=.==0.00 is the cctcl fcr-
mct. lt secifies c lecJin
Jcllcr sin. ccmmcs everv
three Jiits. zerc-sres-
sicn excet fcr the cnes.
tenths. cnJ hnJreJths
csiticns. cnJ c ericJ
cs the Jecimcl cint.
6bag\ahXWbaaXkgcTZX
C14622124.indd 161 9/9/05 10:05:37 AM
&+' B^Xgdhd[iK^hjVaLZW9ZkZadeZg'%%*:megZhh:Y^i^dc/7j^aYVLZWH^iZCdl
N ln Lhe SqlDctcScrce conLrol or Lhe ProducLs Lable, Lhe Add WHFRF Clause dialog box
speciies ConLrol in Lhe Source drop-down lisL, and DrcDcwnlist1 in Lhe ConLrol lD
drop-down lisL. (1he ConLrol lD drop-down lisL is in Lhe ParameLer ProperLies rame).
1he sample iles also include a SeekProducLs.aspx page where visiLors can Lype a parLial
producL descripLion inLo a LexL box, click a Summon buLLon, and receive a lisL o maLching
producLs. 1his page also resembles Lhe CosLumes.aspx page, excepL LhaL iL includes.
N A 1ext3cx conLrol named txtRne.
N A 3ttcn conLrol named btnSmmcn LhaL submiLs Lhe orm.
N 1he ollowing condiLion in Lhe Add WHFRF Clause dialog box o iLs SqlDctcScrce
conLrol.
N 8dajbc ProducLName
N DeZgVidg LlKF
N HdjgXZ ConLrol
N 8dcigda>9 LxLRune
N A Dctc1extlielJ properLy LhaL speciies which ield supplies Lhe visible LexL.
N A NcvicteURl properLy LhaL speciies which ield supplies Lhe LargeL URL.
6bag\ahXWYeb`cTZX$)%
ASP.Nl1 ccn clsc fcrmct
Jctes cnJ times. lcr excmle.
{0.JJ-MMM-vvvv} wclJ Jis-
lcv Hcrrv HcJinis birthJcv
cs 24-Mcr-1874.
When vc secifv c cstcm
Jctc fcrmct strin. vc mst
clsc secifv HtmllnccJe=lclse.
lcr mcre infcrmcticn.
lccl lcrmct Secifiers
in the viscl Web Develcer
Hel inJex.
9^heaVn^c\8dbeaZm
EV\Z:aZbZcih
3v Jefclt. the Cridview.
DeLailsview. cnJ Formview
ccntrcls Jislcv cll infcrmc-
ticn cs lcin text. 1c Jislcv
infcrmcticn cs c checl bcx.
hverlinl. ictre. cr cther
H1Ml element.
&# Ccnfire the ccntrcl cs
scl ntil vc et tc the
lielJs Jiclc bcx shcwn in
lire 14-8.
6bag\ahXWbaaXkgcTZX
C14622124.indd 162 9/9/05 10:05:38 AM
8]VeiZg&)/9^heaVn^c\9ViVWVhZ>c[dgbVi^dc &+(
>cHjbbVgn
visual Web Developer can creaLe aLLracLive pages LhaL display daLabase inormaLion in a
varieLy o ways. 1o do Lhis wiLhouL wriLing any program code requires Lhree componenLs.
a daLa connecLion LhaL provides a paLhway Lo Lhe daLabase, a daLa source LhaL reLrieves
records rom Lhe daLa connecLion, and inally a daLa-bound conLrol (oLen a CriJview.
Detcilsview. or lcrmview conLrol) LhaL converLs Lhe daLa Lo H1ML or display.
1he nexL chapLer will explain how Lhis same collecLion o conLrols can updaLe
inormaLion in daLabases.
6bag\ahXWYeb`cTZX$)&
'# ln the Avcilcble lielJs bcx.
select the tve cf ctt
ccntrcl vc wcnt. then clicl
the AJJ bttcn. 1his will
cJJ cn entrv tc the SelecteJ
lielJs bcx.
(# With this new entrv
selecteJ. ccnfire ct
lecst the DctclielJ cnJ
HecJer1ext rcerties
(cr their eqivclents} in the
3cnJlielJ Prcerties bcx
ct the riht.
As vc Jc this. vc shclJ
be recreJ fcr scme vcric-
ticn cmcn ctt ccntrcls. A
hverlinl fielJ. fcr excmle. hcs
nc DctclielJ rcertv. lnstecJ.
it hcs.
A Jctc1extlielJ rcertv
thct secifies which fielJ
slies the visible text.
A ncvicteURl rcertv
thct secifies which fielJ
slies the tcret URl.
C14622124.indd 163 9/9/05 10:05:38 AM
C14622124.indd 164 9/9/05 10:05:39 AM
l65
|o|e 1'
@T\agT\a\aZ
7TgTUTfX
<aYbe`Tg\ba
&*
Hf\aZT;f]XJ]Yk6bageb_
gbHcWTgXTaW7X_XgX
EXVbeWf$))
Hf\aZT8YhU]`gJ]Yk
6bageb_gb4WW
EXVbeWf$),
ReLrieving, organizing, and displaying valuable inormaLion is usually a
rewarding experience. ou enLer a liLLle daLa and geL a loL o inormaLion
back. However, Lhe preliminary sLep o adding records Lo a daLabase is less
un. ou enLer a loL o daLa and receive ew shorL-Lerm rewards. NeverLheless,
someone has Lo enLer Lhe daLa your siLe requires. 1his chapLer explains how
you can use Lhe CriJview conLrol rom Lhe previous chapLer Lo updaLe or
deleLe records, and how you can use Lhe Detcilsview conLrol Lo add records.
1he chapLer also menLions some addiLional uncLions LhaL Lhese conLrols
provide. 8esL o all, none o Lhese Lechniques requires wriLing any code.
C15322124.indd 165 9/30/05 5:16:45 PM
l66 Microsoft VisuaI web DeveIoper 2005 xpress dition. BuiId a web Site Now!
Using a <g^YK^Zl ControI to Update and DeIete kecords
Figure 5- illusLraLes Lhe
CriJview approach Lo updaLing
records. For each record, Lhe grid
displays any combinaLion you
wanL o Lhese special links.
N dit Uses an H1ML orm
ield Lo display each updaLable
ield a record conLains. 1he
Web visiLor modiies Lhese
values as necessary, Lhen clicks
an UpdaLe link Lo save Lhe
changes or a Cancel link Lo
abandon Lhem. 1he igure
shows Lhis in progress.
N DeIete lmmediaLely deleLes
Lhe corresponding record.
1here's no, "Are you sure"
prompL.
N SeIect Marks Lhe correspond-
ing record as currenL. 1he
page in Lhe igure doesn'L use
Lhis opLion. For more inorma-
Lion abouL Lhe way Lhis opLion
works, reer Lo Lhe accompa-
nying sidebar LiLled, "Double
8inding. NoL an Fscape 1rick."
;^\jgZ&*"&
|e :|o o C|d\|e. .c|c| |c
:Jo|e o Jo|o|oe. ||e v|||c |||
.||.| |J||. cve|/e ||e |cm ||e|J.
oJ ||e .||.| ||e JJo|e |||
C15322124.indd 166 9/30/05 5:16:47 PM
Chapter l5. Maintaining Database lnformation l67
TO CONllGUk A *5,'9,(: CONTkOL TO PklOkM UPDATS
$
\a|e sJe |a |e daabase ab|e |as a p|nay |ey |o e.anp|e. |g|c||c| |e ab|e |r Daabase
|.p|oe. c|oose Cper Tab|e De|r||or. ard na|e sJe |a |e |e|d (o eac| o |e |e|ds. | |ee's
noe |ar ore) |a Jr|oJe|y |der||es eac| ecod |as a |ey |cor as s|o.r be|o.
9djWaZ7^cY^c\/
CdiVc:hXVeZIg^X`
ln ASP.Nl1 2.0. its cll riht
fcr twc Jifferent ccntrcls tc binJ
tc the scme Jctc scrce. 3cth
ccntrcls simlv Jislcv the scme
Jctc.
lf. fcr excmle. vc binJ
c DeLailsview ccntrcl (which
Jislcvs cne reccrJ ct c time}
cnJ c Cridview ccntrcl (which
Jislcvs severcl reccrJs bt
selects cne ct c time} tc the
scme Jctc scrce. the twc
ccntrcls will clwcvs Jislcv
the scme crrent reccrJ.
| |ey dor'. se|ec |e |e|d (o |e|ds) |a s|oJ|d seve as |e p|nay |ey. |g|c||c| |e se|ec|or. ard
|er c|oose GYhDf]aUfm?Ym on |e s|ocJ nerJ
%
Cor|gJe |e daa soJce ard |e |JV|ew coro| so |ey d|sp|ay |e ecods ard |e|ds yoJ .ar
|o.se |e page o na|e sJe |e d|sp|ay Jrc|or |s .o||rg pope|y
&

\a|e sJe |e daa soJce |s cor|gJed .|| |NS||T. ||D/T|. ard D|||T| saeners To c|ec| ||s
Q Se|ec Cor|gJe Daa SoJce on |e coro|'s as| nerJ
Q C||c| |e Ne. bJor o d|sp|ay |e Cor|gJe T|e Se|ec Saener d|a|og bo.
Q | |e /dvarced bJor |s erab|ed. c||c| | \|er |e /dvarced SO| Cerea|or Cp|ors d|a|og bo.
appeas. na|e sJe |e Cereae |NS||T. ||D/T|. /rd D|||T| Saeners c|ec| bo. |s se|eced as
s|o.r |r ||gJe 1'
| e||e |e /dvarced bJor o |e Cereae |NS||T. ||D/T|. /rd D|||T| Saeners
c|ec| bo. |s d|nned. ard | |e c|ec| bo. |sr' se|eced. |er c|ose |e /dvarced SO|
Cerea|or Cp|ors d|a|og bo. (| |'s oper) ard a|e e||e o |ese ac|ors |r |e
Cor|gJe T|e Se|ec Saener d|a|og bo.
;^\jgZ&*"'
|| /c: |o |c :e o Jo|o c:.e |c
:Jo||o. /c: m:| e|e.| ||e |||
.|e.| |cx | ||| J|o|co |cx
/ |ey |cor |rd|caes
|e|ds |r |e p|nay |ey
C15322124.indd 167 9/30/05 5:16:49 PM
l68 Microsoft VisuaI web DeveIoper 2005 xpress dition. BuiId a web Site Now!
Q \|| |e Spec|y / CJson SO| Saener C Soed |ocedJe op|or se|eced. c||c| |e Ne. bJor o
d|sp|ay |e De|re CJson Saeners C Soed |ocedJes d|a|og bo. T|er. na|e sJe |a |e
||D/T|. |NS||T. ard D|||T| abs a|| d|sp|ay va||d SO| saeners
Q Se|ec |e Spec|y Co|Jnrs |on / Tab|e C \|e. op|or. ecor|gJe |e S|||CT saener on scac|.
|er c||c| |e /dvarced bJor ard se|ec |e Cereae |NS||T. ||D/T|. /rd D|||T| Saeners c|ec|
bo. (|o |e|p ecor|gJ|rg |e S|||CT saener. ee o C|ape 14)
'
| yoJ'e ecea|rg |e sanp|e s|e. ceae a re. /S|N|T \eb page |r a o|de raned secJe.
rane | |pdae|odJcsasp.. ard add 'o||o|o'c:.e ard |JV|ew coro|s as yoJ d|d |r |e
pev|oJs c|ape
(

D|sp|ay |e |JV|ew coro|'s as| nerJ ard se|ec ary conb|ra|or o |ese c|ec| bo.es
Q nabIe diting Se|ec ||s c|ec| bo. | yoJ .ar |e CriJview coro| o nod|y e.|s|rg daabase
ecods
Q nabIe DeIeting Se|ec ||s c|ec| bo. | yoJ .ar |e CriJview coro| o de|ee e.|s|rg daabase
ecods
Q nabIe SeIection Se|ec ||s c|ec| bo. | yoJ .ar |e CriJview coro| o des|grae ecods as cJer
||e|d va|Jes on |a ecod .||| |er appea |r ary o|e coro|s boJrd o |e sane daa soJce
)

Save |e page. v|e. | |r a bo.se. ard es
1he sample iles or Lhe ConLosoMagic siLe include a ProducLUpdaLe.aspx page LhaL
illusLraLes Lhese Lechniques. 1his page resides in a subolder named /secure/. ChapLer 7
will explain how Lo sLop unauLhorized visiLors rom using pages in LhaL older.
C15322124.indd 168 9/30/05 5:16:49 PM
Chapter l5. Maintaining Database lnformation l69
Using a 9ZiV^ahK^Zl ControI to Add kecords
Using a CriJview conLrol Lo updaLe or deleLe records is simple and inLuiLive. Using a
CriJview conLrol Lo add records, however, requires wriLing some airly complicaLed program
code. 1o add records wiLhouL wriLing any program code aL all, you can use a Detcilsview
conLrol.
1o creaLe a page LhaL uses a Detcilsview conLrol or adding records Lo Lhe ProducLs Lable
in Lhe ConLoso Magic daLabase, proceed as ollows.
TO CkAT A PAG THAT USS A 9:I6>AHK>:L CONTkOL
$
Ceae a re. b|ar| page raned |odJc/ddasp. ard |ocaed |r |e sane secJe o|de as |e
|odJc|pdaeasp. page on |e pev|oJs sec|or /pp|y ary nase pages o o|e ona|rg
yoJ .ar
%
/dd a 'o||o|o'c:.e coro| o |e page by dagg|rg | on |e Daa goJp |r |e Too|bo.
Cor|gJe ||s daa soJce o access |e |odJcs ab|e |r |e Coroso\ag|c daabase
\|er yoJ ge o |e secord page o |e \|.ad. c||c| |e 5XjUbWYX bJor ard na|e sJe |a |e
Cereae |NS||T. ||D/T|. /rd D|||T| Saeners c|ec| bo. |s se|eced
&

/dd a |e|o||V|ew coro| o |e page by dagg|rg | on |e Too|bo.
'

Cor|gJe |e o||o.|rg |e|ds or |e as| nerJ o |e re. |e|o||V|ew coro|
Q Choose Data Source Se|ec |e daa soJce yoJ ceaed |r sep
Q nabIe lnserting Se|ec ||s c|ec| bo.
(
S.|c| o |e |ope|es .|rdo. ard na|e sJe |e re. |e|o||V|ew coro| |s se|eced T|er. ve|y
|a |e popey se|rgs |r Tab|e 1'1 ae |r eec
)
Save |e page. v|e. | |r a bo.se. ard es /ry ecods yoJ ceae s|oJ|d appea |e re. |ne yoJ
ees| ary o |e podJc pages
Like the 9ZiV^ahK^Zl controI, a
;dgbK^Zl controI can dispIay,
insert, update, and deIete records.
The ;dgbK^Zl controI is more
fIexibIe but it's aIso more dif-
ficuIt to use. You have to sup-
pIy an HTML tempIate for each
feature you want to use. lf you'd
Iike to see an exampIe that uses
the ;dgbK^Zl controI for add-
ing records, inspect the secure/
ProductAddlormView.aspx page in
the sampIe fiIes.
ABG 8
C15322124.indd 169 9/30/05 5:16:50 PM
l70 Microsoft VisuaI web DeveIoper 2005 xpress dition. BuiId a web Site Now!
Figure 5-8 shows how Lhe ProducLAdd.aspx page looks in a browser. 1o add a ProducL
record, Lhe visiLor would ill in a CaLegory ld, ProducL Name, and ProducL Price, Lhen click
Lhe lnserL link.
IVWaZ&*"&
Dea||s\|e. |ce||e |c ||e
|cJ:.|/JJox |ooe
Property Setting Description
AtcCenerctelnsert3ttcn 1rue Speciies LhaL Lhe Detcilsview conLrol
should display Lhe conLrols or inserLing
daLabase records.
AtcCenercteRcws False Speciies LhaL Lhe Detcilsview conLrol
shouldn'L auLomaLically display daLa-
bound ields.
CssClcss ormbox Speciies a CSS class LhaL ormaLs Lhe
display.
DctckevNcmes ProducLld Speciies Lhe lisL o ields LhaL serve as Lhe
daLabase Lable's primary key.
DctcScrcelJ SqlDaLaSource Speciies Lhe name o Lhe daLa source LhaL
updaLes Lhe daLabase.
DefcltMcJe lnserL Speciies LhaL Lhe Detcilsview conLrol
should remain in lnserL mode aLer an
lnserL has occurred.
HcrizcntclAlin cenLer CenLers Lhe Detcilsview conLrol wiLhin Lhe
available display space.
C15322124.indd 170 9/30/05 5:16:50 PM
Chapter l5. Maintaining Database lnformation l7l
l you like, you can puL boLh Lhe CriJview conLrol rom Lhe previous secLion and Lhe
Detcilsview conLrol rom Lhis secLion on Lhe same Web page, and bind Lhem boLh Lo Lhe
same daLa source.
As a pracLical maLLer, you should probably add boLh o Lhe pages rom Lhis chapLer
Lo Lhe Web.siLemap ile so Lhe siLe's menu sysLem makes Lhem easy Lo ind. ChapLer 7
will explain how Lo hide Lhese menu iLems rom visiLors who don'L have auLhoriLy Lo run
Lhe pages.
;^\jgZ&*"(
c oJJ o Jo|o|oe e.cJ |/ meo c| o
Dea||s\|e. .c|c|. ||e v|||c |/e ||e ew
e.cJ vo|:e ||c ||e |cm ||e|J oJ .||.|
||e |e| |||
C15322124.indd 171 9/30/05 5:16:52 PM
l72 Microsoft VisuaI web DeveIoper 2005 xpress dition. BuiId a web Site Now!
ln Summary.
WiLh jusL a liLLle addiLional coniguraLion, a CriJview conLrol can noL only display daLabase
records, buL updaLe and deleLe Lhem as well. A Detcilsview conLrol can also inserL records,
buL iL only displays one record aL a Lime.
1he nexL chapLer will explain how Lo publish a MicrosoL

SOL Server" daLabase rom


your developmenL siLe Lo a live producLion siLe.
C15322124.indd 172 9/30/05 5:16:52 PM
l73
6bcl\aZTFD?FXeiXe
7TgTUTfX$*'
HaWXefgTaW\aZTaW
6baaXVg\aZgbFD?
FXeiXe$*(
6[TcgXe$)
ChU_\f[\aZ
Lbhe7TgTUTfX
&+
When your Web siLe uses a daLabase and you copy Lhe siLe Lo anoLher Web
server, iL's quiLe common Lo copy Lhe daLabase as well. ln some cases, Lhe
Lwo Web servers and Lhe Lwo daLabase servers are so similar LhaL Lhe same
daLabase seLLings and Lhe same ile locaLions work in boLh siLes wiLhouL
modiicaLion. l you ind yoursel in Lhis siLuaLion, you probably won'L need
Lhis chapLer.
ln a more common scenario, your developmenL daLabase server and
your producLion daLabase server will require dierenL connecLion seLLings
or dierenL ile locaLions, and you'll need Lo ix Lhese seLLings on Lhe
producLion siLe. 1o do Lhis, you'll need Lo know a liLLle abouL MicrosoL


SOL Server", connecLion seLLings, and ccnnecticns strins (which sLore Lhose
seLLings). 1his chapLer will explain Lhe basics.
C16622124.indd 173 9/9/05 10:11:44 AM
l74 Microsoft VisuaI web DeveIoper 2005 xpress dition. BuiId a web Site Now!
Copying a SOL Server Database
MicrosoL has simpliied Lhe Lask o copying SOL Server daLabases rom one compuLer Lo
anoLher. ln many cases, publishing a SOL Server daLabase is jusL as easy as publishing a ile-
orienLed daLabase such as MicrosoL Access. ln no case, however, is iL Lerribly diiculL.
l all Lhe ollowing condiLions are Lrue, publishing your Web siLe and your daLabase
LogeLher is a very easy process.
N 1he source daLabase runs on Lhe same compuLer as Lhe source Web siLe.
N 1he desLinaLion daLabase runs on Lhe same compuLer as Lhe desLinaLion Web siLe.
N 1he source and desLinaLion daLabase servers boLh supporL a new SOL Server 2005 ea-
Lure called user insLances, and LhaL's Lhe approach you plan Lo use.
ou jusL publish Lhe daLabase iles rom Lhe App_DaLa older on Lhe source siLe Lo Lhe
App_DaLa older on Lhe desLinaLion siLe. ln any oLher case, Lhe procedure is a liLLle more
complicaLed. Speciically, you'll need Lo.
l. Find ouL where your daLabase iles reside. 1o do Lhis in MicrosoL visual Web
Developer".
a. Open DaLabase Fxplorer.
b. Double-click any daLa connecLion LhaL poinLs Lo Lhe daLabase.
c. ln Lhe ProperLies window, geL Lhe value o Lhe Primary File PaLh properLy.
2. SLop your local copy o SOL Server. 1his ensures LhaL SOL Server doesn'L have exclusive
conLrol o Lhe daLabase iles, and LhaL all changes Lo Lhe iles are compleLe. 1o do Lhis.
a. Click SLarL, Programs, MicrosoL SOL Server 2005, ConiguraLion 1ools, and SOL
ConiguraLion Manager.
b. When Lhe SOL Server ConiguraLion Manager window appears, selecL SOL Server
2005 Services in Lhe pane aL Lhe leL.
c. ln Lhe pane aL Lhe righL, righL-click SOL Server (SOLFXPRFSS) and choose SLop rom
Lhe shorLcuL menu.
C16622124.indd 174 9/9/05 10:11:45 AM
Chapter l6. PubIishing Your Database l75
SLopping Lhe Windows service SOL Server (SOLFXPRFSS) by any oLher means has Lhe
same eecL. ou can resLarL SOL Server aLer you've copied Lhe iles.
3. Copy Lhe daLabase's .md ile (and .ld ile, i one exisLs) Lo Lhe producLion daLabase serv-
er. 1o geL Lhe exacL locaLion and Lhe necessary upload procedure, ask your l1 or Web
hosL adminisLraLor.
4. Ask Lhe adminisLraLor Lo aLLach Lhe daLabase iles Lo a copy o SOL Server.
5. ObLain a connecLion sLring (or aL leasL connecLion seLLings) rom Lhe adminisLraLor.
6. lnsLall Lhe new connecLion seLLings in Lhe desLinaLion siLe's web.conig ile. A laLer secLion
LiLled, "Using ConnecLion SLrings," will explain how Lo do Lhis.
Among Lhese sLeps, obLaining and Lhen insLalling Lhe new connecLion sLring are likely Lo
be Lhe mosL diiculL. 1o do Lhis successully, you need Lo know someLhing abouL daLabase
connecLion seLLings. 1o undersLand Lhese seLLings, you need Lo know a liLLle abouL SOL
Server. 1he resL o Lhis chapLer explains whaL you need Lo know.
Understanding and Connecting to SOL Server
MicrosoL SOL Server is an enLerprise-class, indusLrial-sLrengLh daLabase sysLem. As such, iL
has a repuLaLion or complexiLy. 1he deeper you delve inLo SOL Server, Lhe more deLails you
can discover.
MicrosoL, however, is dedicaLed Lo ease o use and Lhis includes SOL Server. Fach release
o SOL Server is more powerul, more reliable, more secure, and easier Lo use Lhan Lhe lasL.
SOL Server 2005 conLinues Lhis Lrend and SOL Server 2005 Fxpress FdiLion expands upon iL.
Consider how smooLh and naLural iL was Lo compleLe Lhe examples in ChapLers 8, 4, and
5, all o which used SOL Server Fxpress.
C16622124.indd 175 9/9/05 10:11:45 AM
l76 Microsoft VisuaI web DeveIoper 2005 xpress dition. BuiId a web Site Now!
SOL Server is a netwcrl Jctcbcse. 1his means LhaL Web siLes and oLher applicaLions
inLeracL wiLh SOL Server over netwcrl ccnnecticns, raLher Lhan Lhrough Lhe compuLer's ile
sysLem. Figure 6- represenLs Lhis schemaLically.
SQL Server
Database File
SQL Server
(Second nstance)
Database File
DB Server
File-Oriented Database
(e.g. Microsoft Access)
Network Database
(e.g. Microsoft SQL Server)
ASP.NET Page
Database Driver(s)
Web Server
ASP.NET Page
Database Driver(s)
Web Server
ASP.NET Page
Database Driver(s)
Database File
Web Server
ASP.NET Page
Database Driver(s)
Web Server
;^\jgZ&+"&
J\g[Y\_Xbe\XagXWWTgTUTfXfg[X
WTgTUTfXWe\iXehcWTgXfg[Xc[lf\VT_
WTgTUTfXY\_XfW\eXVg_l!J\g[TaXgjbe^
WTgTUTfXg[XWe\iXeVbaaXVgfgbUTV^
ZebhaWfbYgjTeXehaa\aZbag[XfT`X
beTabg[XeVb`chgXe!G[XUTV^ZebhaW
fbYgjTeXTeU\geTgXfeXdhXfgfYeb`
`h_g\c_XTcc_\VTg\bafTaWc[lf\VT__l
hcWTgXfg[XWTgTUTfXY\_Xf!
1he coniguraLion aL Lhe leL is Lypical o ile-orienLed daLabases such as MicrosoL Access.
1he cliccticn (or clienL) calls a daLabase driver (or, more accuraLely, a stccl o daLabase
drivers) and Lhose drivers physically read and wriLe Lhe daLabase ile.
1he coniguraLion aL Lhe righL illusLraLes a neLwork daLabase such as SOL Server. As
beore, Lhe applicaLions call Lhe daLabase driver. 1haL driver, however, opens a neLwork
connecLion Lo a copy o SOL Server LhaL runs as a background Lask on Lhe same or anoLher
compuLer. SOL Server analyzes incoming requesLs, does Lhe necessary work (including
physical l/O), and sends any resulLs back Lo Lhe clienL compuLer.
1able 6- lisLs some o Lhe mosL common Lop-level daLabase drivers LhaL supporL SOL
Server. 1c-level means LhaL applicaLions inLerace direcLly wiLh Lhese drivers.
VisuaI web DeveIoper aIways uses
HnhiZb#9ViV#Hfa8a^Zci to commu-
nicate with SOL Server. This is the
best choice for any ASP.NT appIi-
cation that uses SOL Server.
ABG 8
C16622124.indd 176 9/9/05 10:11:48 AM
Chapter l6. PubIishing Your Database l77
Using Connection Strings
1he irsL sLep in using any daLabase is Lo open a Jctcbcse ccnnecticn. A series o parameLers
in a ccnnecticn strin Lells Lhe daLabase driver which daLabase Lo open, whaL kind o securiLy
Lo use, and whaL opLions should be in eecL.
visual Web Developer sLores connecLion sLrings in an XML ile named web.conig. Here's
a shorL buL airly Lypical example o Lhis ile. 1he connecLion sLring is Lhe porLion o line 5
shown in green. 1he line breaks are sLricLly or readabiliLy.
01 <?xm] ves1on=1.0 encod1ng=uff-?>
02 <conf1guaf1on
03 xm]ns=hffp://schemas.m1cosoff.com/.NefConf1guaf1on/v2.0>
04 <connecf1on5f1ngs>
0S <add name=ConfosoMag1cConnecf1on5f1ng
connecf1on5f1ng=Dafa 5ouce=.\5OLLXPRL55
AffachDbI1]ename=|DafaD1ecfoy|\ConfosoMag1c.mdf
lnfegafed 5ecu1fy=1ue
use lnsfance=1ue
06 pov1deName=5ysfem.Dafa.5q]C]1enf />
07 </connecf1on5f1ngs>
0 <sysfem.Web>
09 <pages fheme= />
10 </sysfem.Web>
11 </conf1guaf1on>
IVWaZ&+"&
@\VebfbYg7TgTUTfX7e\iXe
GXV[ab_bZ\Xf
Database Driver Year Description
lntroduced
OD3C 992 Open DaLabase ConnecLiviLy
Oll D3 996 ObjecL Linking and Fmbedding - DaLabase
Svstem.Dctc.SqlClient 2002 .NF1 Framework DaLa Provider or SOL Server
C16622124.indd 177 9/9/05 10:11:48 AM
l78 Microsoft VisuaI web DeveIoper 2005 xpress dition. BuiId a web Site Now!
ln Lhis connecLion sLring.
N Data Source Speciies Lhe name o Lhe compuLer where SOL Server is running and, i
necessary, an insLance name. ln Lhe example, a period indicaLes Lhe local compuLer and
SOLFXPRFSS is an instcnce ncme. (An insLance name idenLiies a speciic insLallaLion o
SOL Server.)
N AttachDbliIename Speciies a daLabase ile LhaL you wanL SOL Server Lo use. 1he
expression |DaLaDirecLory| means Lhe Web siLe's App_DaLa older, and ConLosoMagic.md
is Lhe ile LhaL conLains Lhe SOL Server daLabase.
N lntegrated Security=True Speciies LhaL when your Web suiLe connecLs Lo SOL server, iL
will log in using Lhe MicrosoL Windows

accounL LhaL runs ASP.NF1 processes or your


Web siLe. For Lhe developmenL Web server LhaL comes wiLh visual Web Developer, Lhis is
Lhe accounL you used when you logged inLo Windows.
N User lnstance=True Speciies LhaL you wanL SOL Server Lo sLarL a new instcnce o iLsel
(LhaL is, a new running copy) jusL or your Web siLe. 1his insLance will run under Lhe
Windows accounL o Lhe process LhaL requesLed iL. LhaL is, under Lhe accounL LhaL runs
ASP.NF1 processes or your Web siLe.
NoLe LhaL lnLegraLed SecuriLy is a clienL seLLing and User lnsLance is a server seLLing.
l boLh o Lhese seLLings are 1rue.
N 1he SOL clienL and Lhe user insLance o SOL Server will run under Lhe same Windows
accounL (which, on Lhe developmenL Web server, is yours).
N 1he user insLance o SOL Server will have no more (and no ewer) privileges Lhan Lhe
accounL LhaL runs ASP.NF1 process or your Web siLe.
N our Web siLe will have SOL Server adminisLraLor privileges wiLhin Lhe user insLance o
SOL Server.
ConnecLion sLrings o Lhis Lype are very common on Jevelcment compuLers running
boLh visual Web Developer and SOL Server Fxpress. 1he connecLion sLring below is one o
several ormaLs common on rcJcticn Web servers. 1his sLring would replace Lhe porLion o
your Web.conig ile previously shown in green.
C16622124.indd 178 9/9/05 10:11:48 AM
Chapter l6. PubIishing Your Database l79
Dafa 5ouce=saWbox ln1f1a] Cafa]og=ConfosoMag1c use ld=pesfo PassWod=chango
As Lo Lhe parameLers.
N Data Source Speciies Lhe name o Lhe compuLer where SOL Server is running, i an
insLance name had been required, Lhe parameLer value would have been sawbox\
instcnce.
N lnitiaI CataIog Speciies Lhe name o an exisLing daLabase. 1his is a logical name and noL
a physical ile name. SOL Server "remembers" which physical iles conLain each logical
daLabase.
N User ld Provides a username or opening Lhe daLabase.
N Password Provides a password or opening Lhe daLabase.
1his connecLion sLring doesn'L speciy AttcchDblilencme and a ilename because an
adminisLraLor previously creaLed Lhe daLabase or permanenLly aLLached an .md ile. lL
doesn'L speciy lntercteJ Secritv=1re because Lhe adminisLraLor conigured SOL Server Lo
use iLs own user id and password sysLem. 1he User lJ and PcsswcrJ parameLers speciy Lhose
values.
l Lhe adminisLraLor wanLed SOL Server clienL applicaLions Lo presenL Windows accounLs
as credenLials, Lhe connecLion sLring would look like Lhis.
Dafa 5ouce=saWbox ln1f1a] Cafa]og=ConfosoMag1c lnfegafed 5ecu1fy=1ue
1he adminisLraLor would also conigure SOL Server so Lhe accounL LhaL runs ASP.NF1
processes or your Web siLe has access Lo Lhe necessary daLabases.
1able 6-2 summarizes Lhe mosL common parameLers LhaL appear in SOL Server
connecLion sLrings. ou don'L have Lo memorize all o Lhese, buL you shclJ keep Lhis lisL
handy and remember LhaL connecLion sLrings provide seLLings or opening a daLabase.
Parameter Description
when TabIe l6-2 groups two or
more parameter names into one
tabIe row, those parameter names
are equivaIent.
ABG 8
C16622124.indd 179 9/9/05 10:11:49 AM
l80 Microsoft VisuaI web DeveIoper 2005 xpress dition. BuiId a web Site Now!
IVWaZ&+"'
FD?FXeiXe6baaXVg\baFge\aZ
CTeT`XgXef
Parameter Description
Dctc Scrce. 1he compuLer name or neLwork address o Lhe SOL Server
Server. LhaL manages your daLabase. values seL Lo (lcccl} or a period
AJJress. (.) indicaLe Lhe local compuLer.
AJJr.
Netwcrl AJJress
Netwcrl librcrv. 1he neLwork library LhaL Lhe clienL compuLer will use when
NeL communicaLing wiLh SOL Server. ln essence, Lhis deLermines
Lhe communicaLion mode. 1able 6-8 lisLs Lhe supporLed
values. NoLe LhaL any library you choose musL be presenL on
boLh Lhe clienL and server compuLers, and LhaL Lhe neLwork
connecLing Lhem musL supporL Lhe given proLocol.
l you speciy a local server-or example, by coding
(lcccl} or a period (.)-and don'L speciy a neLwork library,
Lhe deaulL is shared memory. OLherwise, Lhe deaulL is
dbmssocn (1CP/lP).
Dctcbcse. 1he logical name o Lhe daLabase.
lniticl Cctclcg
AttcchDblilencme. 1he name o Lhe primary .md ile, including Lhe ull paLh
lxtenJeJ Prcerties. name, o an aLLachable daLabase.
lniticl lile Ncme
l you also speciy Lhe Dctcbcse parameLer, LhaL value
will become Lhe logical name o Lhe daLabase you aLLach.
OLherwise, SOL Server will use Lhe ile name base and
exLension as Lhe daLabase name.
6bag\ahXWbaaXkgcTZX
C16622124.indd 180 9/9/05 10:11:49 AM
Chapter l6. PubIishing Your Database l8l
Parameter Description
lntercteJ Secritv. When fclse, you musL code Lhe User lD and PcsswcrJ
1rsteJ_Ccnnecticn parameLers wiLh Lhe idenLiy o a SOL Server accounL LhaL
has permission Lo open your daLabase. 1his is Lhe deaulL.
1he values fclse and nc are equivalenL.
When tre, SOL Server will base permissions on Lhe Windows
accounL LhaL runs ASP.NF1 processes or your Web siLe. 1he
values tre, ves. and ssi are equivalenL.
User ld 1he SOL Server login accounL. Code Lhis parameLer only i
lnLegraLed SecuriLy is fclse.
PcsswcrJ. 1he SOL Server login accounL password. Code Lhis parameLer
Pwd only i lnLegraLed SecuriLy is fclse.
User lnstcnce l tre, SOL Server will creaLe a new insLance o iLsel Lo
service Lhe connecLion. 1haL insLance will run under Lhe
clienL compuLer's Windows login accounL, buL LreaL LhaL
accounL as a SOL Server adminisLraLor.
1he deaulL is fclse.
IVWaZ&+"(
FD?FXeiXeAXgjbe^?\UeTe\Xf
Library Name Description
ldbnmpnLw Named Pipes Windows neLworking
dbmsrpcn MulLiproLocol Windows RPC
dbmsadsn Apple 1alk Apple DaLasLream ProLocol (ADSP)
dbmslpcn Shared Memory Process-Lo-process wiLhin one compuLer
dbmsspxn lPX/SPX Novell NeLware
dbmssocn 1CP/lP lnLerneL sockeLs
6bag\ahXWYeb`cTZX$+#
C16622124.indd 181 9/9/05 10:11:50 AM
l82 Microsoft VisuaI web DeveIoper 2005 xpress dition. BuiId a web Site Now!
Sharing a SingIe Copy of SOL Server
MulLiple applicaLions, running on any combinaLion o compuLers, can connecL Lo SOL Server
and use iLs capabiliLies simulLaneously. 1his is one o Lhe reasons SOL Server can handle
much heavier loads Lhan a ile-orienLed daLabase sysLem. l Lwo or more applicaLions submiL
conlicLing requesLs-perhaps aLLempLing Lo updaLe Lhe same record-SOL Server arbiLraLes
Lhese conlicLs much more eicienLly Lhan a ile-orienLed daLabase like Access.
Administering Shared SOL Servers
When several applicaLions or developmenL groups use Lhe same copy o SOL Server, iL's
quiLe normal or none o Lhem Lo have AdminisLraLor privileges. 1his keeps Lhe applicaLions
(or developmenL groups) secure rom each oLher.
ln shared environmenLs, a daLabase adminisLraLor (D8A) usually receives requesLs or new
daLabases, securiLy changes, backups, resLores, and oLher Lasks rom developers, veriies Lheir
auLhenLiciLy, and Lhen perorms Lhe work. 1his means, o course, LhaL Lhe developers musL
submiL service requesLs and waiL or Lhe D8A Lo compleLe Lhem. 1he D8A Lypically works in
Lhe l1 deparLmenL or aL a hosLing company.
Server lnstances
A single compuLer can run several instcnces (LhaL is, ccies) o SOL Server. A server insLance
is a sLand-alone copy o SOL Server, independenL o any oLher insLances on Lhe same com-
puLer. For example, each insLance could be a dierenL version. Fach insLance runs as iLs own
Windows service. An adminisLraLor creaLes server insLances by running SOL Server SeLup or
each one. Fach server insLance on Lhe same compuLer has a dierenL instcnce ncme.
ln Figure 6-, Lwo applicaLions are accessing Lhe irsL insLance o SOL Server, and one
applicaLion is accessing Lhe second insLance. However, each copy o SOL Server is a ull
server insLance. l Lhe need arose, eiLher could service dozens or hundreds o applicaLions aL
once.
C16622124.indd 182 9/9/05 10:11:50 AM
Chapter l6. PubIishing Your Database l83
User lnstances
SOL Server 2005 and SOL Server Fxpress boLh supporL a new kind o SOL Server insLancing.
ser instcnces. When an applicaLion requesLs a user insLance, SOL Server.
Q Loads a new copy o iLsel inLo memory.
Q Runs Lhe new insLance wiLh LhaL applicaLion's Windows logon accounL. (For an ASP.NF1
Web siLe, Lhis is Lhe accounL LhaL runs Lhe siLe's ASP.NF1 processes.)
Q CranL's Lhe applicaLion's logon accounL AdminisLraLor permissions, buL only wiLhin LhaL
insLance.
Q 1erminaLes Lhe insLance aLer a period o inacLiviLy.
l you creaLe a daLabase in visual Web Developer, i a Web siLe is open, and i SOL Server
2005 or SOL Server Fxpress is running on Lhe same machine, Lhen visual Web Developer will.
Q Ask SOL Server Lo sLarL a user insLance.
Q Use LhaL insLance Lo creaLe LhaL daLabase, locaLing iLs iles in Lhe siLe's App_DaLa older.
Q Conigure Lhe siLe Lo requesL a user insLance whenever iL opens Lhe daLabase.
1his is a very useul approach because iL gives you, as Lhe Web developer, permission
Lo creaLe daLabases and perorm oLher adminisLraLive Lasks wiLh no securiLy resLricLions.
However, because Lhe user insLance is running under Lhe same Windows logon accounL as
your Web siLe, iL can'L access, modiy, or adminisLer daLabases LhaL belong Lo oLher siLes.
When SOL Server is running as a user insLance, Lhe ollowing limiLaLions are in eecL.
Q AuLomaLic replicaLion is unavailable.
Q SOL Server usernames and passwords are unavailable. ou musL use Windows auLhenLi-
caLion.
Q 1he neLwork proLocol musL be local named pipes (LhaL is, shared memory). 1his is auLo-
maLic, buL means Lhe clienL and server musL run on Lhe same compuLer.
Q A user insLance shares Lhe regisLry enLries o Lhe server insLance LhaL creaLed iL.
C16622124.indd 183 9/9/05 10:11:50 AM
l84 Microsoft VisuaI web DeveIoper 2005 xpress dition. BuiId a web Site Now!
Q ou musL access Lhe daLabase Lhrough ADO.NF1. Code LhaL visual Web Developer creaLes
Lhrough iLs graphical inLerace always saLisies Lhis requiremenL. Older programs LhaL use
OD8C or OLF D8 will ail.nces.
Attaching Database liIes
When you ask SOL Server Lo creaLe a daLabase, iL musL obLain disk space or sLoring Lhe daLa.
lL does Lhis by creaLing a ile wiLh an .md ilename exLension and Lhen cttcchin LhaL ile Lo
Lhe new daLabase. When you begin Lo use Lhe daLabase, SOL Server also creaLes a log ile
wiLh an .ld ilename exLension.
l you copy an .md ile (and iLs companion .ld ile, i any), you can cttcch Lhe copied
iles Lo any oLher insLance o SOL Server. 1he SOL Server LhaL aLLaches Lhe .md and .ld iles
can Lhen deliver a copied version o Lhe daLabase Lo any applicaLion LhaL needs iL. 1here are
Lwo ways o aLLaching daLabases.
Q 1hrough adminisLraLive Lools such as SOL Server FnLerprise Manager or MicrosoL visual
SLudio. 1his is Lhe normal approach or shared copies o SOL Server.
N 8y using Lhe AttcchD3lileNcme connecLion sLring parameLer. 1his is Lhe normal approach
or user insLances.
Understanding Logins
Fvery copy o SOL Server veriies Lhe idenLiLy o each clienL LhaL aLLempLs a connecLion and
Lries Lo access iLs resources. SOL Server uses Lhis idenLiLy Lo deLermine whaL privileges Lhe cli-
enL has on Lhe server as a whole, and also or each o Lhe server's daLabases. 1wo very dier-
enL Lypes o accounLs are valid or Lhis purpose.
Q windows Accounts Fvery process on every Windows compuLer runs under a Windows
login accounL. On lnLerneL lnormaLion Server (llS), or example, many Web siLes use a
local accounL named lUSR_ccmterncmeor non-ASP.NF1 processes. ln addiLion.
Q On llS 5.0 ASP.NF1 processes run by deaulL under a local accounL named ASPNF1.
Q On llS 6.0, ASP.NF1 processes run by deaulL under a local accounL named NeLwork
Services.
C16622124.indd 184 9/9/05 10:11:51 AM
Chapter l6. PubIishing Your Database l85
DespiLe Lhese deaulLs, an adminisLraLor can conigure any Web siLe Lo run under any
suiLably-conigured Windows accounL (local or domain).
l your connecLion sLring speciies lntercteJ Secritv=tre or 1rsteJ_Ccnnecticn=tre,
SOL Server will deLermine Lhe siLe's daLabase privileges based on Lhe Windows accounL
Lhe siLe uses Lo run ASP.NF1 processes.
NoLe LhaL i llS and SOL Server are running on dierenL machines, Lhis Windows accounL
musL be a domain accounL, and Lhe Lwo servers need Lo be in Lhe same or LrusLing
domains. A local accounL on Lhe llS machine wouldn'L be valid on Lhe SOL Server
machine, and vice versa.
Q SOL Server Accounts l an adminisLraLor decides iL isn'L pracLical Lo seL up Windows
accounLs or every Web siLe (or perhaps or every virLual server), Lhe adminisLraLor can
choose Lo use SOL Server accounLs insLead.
1hese accounLs exisL solely wiLhin a single copy o SOL Server. 1hey have noLhing do wiLh
Windows login accounLs or AcLive DirecLory direcLory service. A cauLion. because Lhey
use less encrypLion, Lhey're noL as secure as Windows accounLs.
l your connecLion sLring speciies (or deaulLs Lo) lntercteJ Secritv=fclse or iLs
equivalenL, 1rsteJ_Ccnnecticn=fclse, iL musL also conLain User lJ= and PcsswcrJ=
parameLers Lo speciy Lhe SOL Server username and password.
How VisuaI web DeveIoper Uses SOL Server
MicrosoL has Lried very hard Lo ensure LhaL you never encounLer securiLy problems while
developing Web siLes on your own compuLer. As a resulL, on a Windows compuLer running
visual Web Developer and SOL Server Fxpress.
Q 1he developmenL Web server runs under Lhe Windows accounL you logged in wiLh.
Q 1he Windows accounL LhaL insLalled SOL Server Fxpress (probably yours) will be an
adminisLraLor on LhaL copy o SOL Server Fxpress.
C16622124.indd 185 9/9/05 10:11:51 AM
l86 Microsoft VisuaI web DeveIoper 2005 xpress dition. BuiId a web Site Now!
Q All your connecLion sLrings will deaulL Lo lntercteJ Secritv=tre.
Q Fven i you didn'L insLall Lhe compuLer's copy o SOL Server Fxpress, you can geL SOL
Server adminisLraLive righLs by requesLing a ser instcnce in your connecLion sLring. 1he
secLion, "User lnstcnces. earlier in Lhis chapLer explained how Lhis works.
l, however, you're using a cenLrally-managed and shared SOL Server or developmenL
(or, even more likely, on your producLion siLe) Lhen you may need Lo adjusL your connecLion
sLrings Lo iL your environmenL. A previous secLion in Lhis chapLer, "Using ConnecLion SLrings,"
explained how Lo do Lhis.
ln Summary.
WiLh Lhe inLroducLion o visual Web Developer and SOL Server Fxpress, MicrosoL has made
using SOL Server as easy as using ile-orienLed daLabases like MicrosoL Access.
l Lhe source and desLinaLion daLabase servers boLh supporL user insLances, you can
simply publish your SOL Server daLabase iles wiLh Lhe resL o your Web siLe.
l noL, jusL copy your daLabase iles where Lhe desLinaLion daLabase adminisLraLor
insLrucLs you, and Lhen conigure Lhe desLinaLion Web siLe's connecLion parameLers
accordingly.
1he nexL chapLer will explain how Lo idenLiy your Web visiLors, how Lo proLecL parLs o
your siLe rom unauLhorized visiLors, and how Lo remember seLLings and preerences or each
idenLiied visiLor.
C16622124.indd 186 9/9/05 10:11:52 AM
CW-1
Chapter 17
Controlling
Access to
Your Site
17
The sample site for this chap-
ter resides in a folder named
ContosoMagic17.
NOT E
Configuring Web Site
Security, 184
Adding Login Controls to
Your Site, 193
Hiding Menu Options for
Secured Pages, 197
Publishing Security
Settings, 199
For most Web pages, popularity is the best sign of success. The more people
access your page, the grander the achievement.
For certain pages, however, its critical to block, rather than attract,
visitors. For example, you may want visitors to identify themselves before
accessing certain pages. In other cases, such as the Add Products and
Update Products pages in Chapter 15, youll want to strictly control which
visitors have access. ASP.NET 2.0 has built-in features that satisfy such
requirements. Whats more, Microsoft Visual Web Developer makes
these features very easy to use. You can finish the entire job using only the
graphical interface, and without writing any program code.
C17622124.indd 1 9/11/05 4:53:45 PM
CW-2 Microsoft Visual Web Developer 2005 Express Edition: Build a Web Site Now!
Configuring Web Site Security
Controlling security for an ASP.NET Web site involves two quite different tasks. This section
describes the first task, which is configuring the Web site with the security features and rules
you want. The section Adding Login Controls to Your Site will describe the second task,
which is creating Web pages that handle logins, password changes, self-registrations, and
other security features that visitors use.
To configure security settings for your site, open the site in Visual Web Developer
and choose ASP.NET Configuration from the Website menu. This displays the Web Site
Administration Tool page shown in Figure 17-1.
Figure 17-1
This is the home page for configur-
ing Web site security on Visual Web
Developers built-in Web server.
C17622124.indd 2 9/11/05 4:53:47 PM
Chapter 17: Controlling Access to Your Site CW-3
ASP.NET provides a Security Setup Wizard that makes it easy to configure your site the
first time. Before running that wizard, however, you should configure the sites SMTP e-mail
settings and its authentication provider.
Configuring SMTP E-Mail Settings
A sites SMTP e-mail settings specify the server, From address, and security settings for
any security-related e-mail that ASP.NET sends.
TO CONFIGURE SMTP E-MAIL SETTINGS:
1
Click the Application tab or the Application Configuration link on the Web Site Administration
Tools home page.
2
When the page reappears with the Application tab selected, click the Configure SMTP E-Mail
Settings link that appears in the middle of the page.
3
When a page displaying the Configure SMTP Settings box shown in Figure 17-2 appears, configure
these settings:
Server Name Enter the DNS name or IP address of the SMTP e-mail server that will relay any security-
related e-mail to Web visitors.
Server Port Specify the port number where the SMTP server listens. Normally this is 25, but some
administrators choose another number.
From Specify the e-mail address that will appear in the From: line of any security-related messages from
your site. This doesnt need to be a real address, but it does need to satisfy any rules that the e-mail
server enforces.
Authentication: None Select this button if the SMTP server accepts e-mail without knowing the send-
ers identity.
Authentication: Basic Select this button if the SMTP server accepts e-mail only from senders who sup-
ply a valid user name and password. Then, specify the user name and password in the appropriate
boxes.
Authentication: NTLM Select this button if the SMPT server accepts e-mail only from processes that
run under a known Microsoft Windows

login account. This will be the account that runs ASP.NET pro-
cesses for your web site.
C17622124.indd 3 9/11/05 4:53:47 PM
CW-4 Microsoft Visual Web Developer 2005 Express Edition: Build a Web Site Now!
4

Click the Save button and then, when the confirmation message appears, click the OK button. SMTP e-mail servers use a variety
of methods to block unsolicited
mass mailings (spam). For exam-
ple, they may only accept e-mail
with known addresses (or at least
known domains) listed in the From
field, or e-mail from IP addresses
on your companys or connectivity
providers network.
NOT E
Figure 17-2
This page specifies the SMTP e-mail
server and related settings ASP.NET
should use when sending security-
related e-mail.
Configuring an Authentication Provider
This setting controls the type of database that stores the login accounts, roles, role member-
ships, and other administrative data for your site. This is fairly simple because Visual Web
Developer doesnt support very many choices.
C17622124.indd 4 9/11/05 4:53:48 PM
Chapter 17: Controlling Access to Your Site CW-5
TO CONFIGURE AN AUTHENTICATION PROVIDER
1
On the Web Site Administration Tool home page, click either the Provider tab or the Provider
Configuration link.
2

To use the same type of database for all your security data:
Click the link titled Select A Single Provider For All Site Management Data.
When a page with a Provider box appears, select the provider you want. In all probability, the only choice
will be AspNetSqlProvider.
Click the Test link to verify that the provider is installed and working. A Provider Management box should
report, Successfully established a connection to the database. Click the OK button to close this box.
To save the configuration, click the Back button at the bottom of the Web page.
3

To use different types of databases for some security data:
Click the link titled Select A Different Provider For Each Feature (Advanced). This will display a page with
two boxes titled Membership Provider and Role Provider.
The Membership Provider box specifies the type of database to use for storing login accounts. The only
choice will be AspNetSqlMembershipProvider, which corresponds to Microsoft

SQL Server.
The Role Provider box specifies the type of database to use for storing security groups. Select
AspNetSqlRoleProvider (which uses SQL Server) or AspNetWindowsTokenRoleProvider (which uses
Windows groups).
Click Back to save the configuration.
As a practical matter, you should probably select a single provider (SQL Server) for all site
management data unless your site resides on an intranet and you plan to use both Windows
accounts and Windows security groups for controlling access.
Running the Security Setup Wizard
This wizard configures most of the security settings for your site, including an initial set of
login accounts and access rules.
C17622124.indd 5 9/11/05 4:53:49 PM
CW-6 Microsoft Visual Web Developer 2005 Express Edition: Build a Web Site Now!
Figure 17-3
This page specifies whether to authenticate
visitors by using Windows accounts or by
using custom accounts stored in a SQL Server
database.
TO RUN THE SECURITY SETUP WIZARD
1
On the Web Site Administration Tools home page, click either
the Security tab or the Security link.
2
When a page with the Security tab highlighted appears, click the
link titled Use The Security Setup Wizard To Configure
Security Step By Step.
3
When the wizards Welcome page appears, read the introductory
information and then click the Next button.
4
On the Select Access Method page shown in Figure 17-3, select
either:
From The Internet if you want your site to have its own database
of login accounts. This is the usual choice for sites located on the
Internet.
From A Local Area Network if you want to use existing Windows
login accounts for controlling access to your site. This is the usual
choice for sites on a company intranet.
After making your selection, click the Next button.
C17622124.indd 6 9/11/05 4:53:50 PM
Chapter 17: Controlling Access to Your Site CW-7
5
If you chose From A Local Area Network in
step 4, skip to step 6.
If you chose From The Internet, a Data Store wizard
page will appear. Read the information it presents
and then click the Next button. (To change any set-
tings this page mentions, refer to the previous sec-
tion titled, Configuring an Authentication Provider.)
6
When the Define Roles page initially appears,
it will contain a single check box titled Enable
Roles For This Web Site. If you want some registered
visitors to have different privileges than others,
select this check box. If all registered visitors will
have the same privileges, clear it. Click the Next
button to continue.
7
If you enabled roles in step 6, the Define Roles
page will change to resemble Figure 17-4. For
each role you plan to use, enter its name in the
New Role Name box and then click the Add Role
button. Each role you create will appear in the
Existing Roles box. When youre done, click the
Next button.
Figure 17-4
Use this wizard page to create any security
groups (roles) that your site needs.
C17622124.indd 7 9/11/05 4:53:51 PM
CW-8 Microsoft Visual Web Developer 2005 Express Edition: Build a Web Site Now!
8
When the Add New Users wizard page shown
in Figure 17-5 appears, fill out the Create User
form and click the Create User button once for
each login account you want the site to have. Keep
these points in mind:
The User Name field is a login name, not a legal
name. Specify a value like bzighetti or barzig,
rather than Barbara Zighetti.
Passwords must be at least eight characters long
and contain at least one letter, one numeric digit,
and one special character.
If a visitor forgets his or her password but can
correctly answer the security question, ASP.NET
will reset the password and send the new pass-
word to the given e-mail address.
The Active User check box in the lower left corner
determines whether the visitor can log in. To pre-
vent an account from logging in, clear this box.
If you wish, you can create additional login
accounts later, or let visitors create their own
accounts.
Once youve created all the login accounts you
need, click the Next button.
Figure 17-5
This page can create as many new
login accounts as you want. Enter the
data for each account and then click
the Create User button.
C17622124.indd 8 9/11/05 4:53:52 PM
Chapter 17: Controlling Access to Your Site CW-9
9
On the Add New Access Rules page shown in Figure 17-5, perform the following steps for each folder
you want to secure:
a. Under the Select A Directory For This Rule heading, expand the folder tree as necessary and then select
the folder you want to configure.
b. Under the Rule Applies To heading, specify who the rule should affect. Table 17-1 explains the available
options.
c. Under the Permission heading, select the Allow option if you want the rule to grant access to any visitors
who match the rule. If you want the rule to block access to any matching visitors, select the Deny option.
d. To save the rule, click the Add This Rule button.
You can create as many rules as you like, whether for the same folder or different folders. Figure 17-6, for
example, shows three rules all assigned to the secure folder.
Figure 17-6
This Web page creates and modifies access
rules for any folder you select.
Dont create access rules that
block anonymous visitors from
your sites root folder. That would
make your login page inaccessible.
T I P
C17622124.indd 9 9/11/05 4:53:53 PM
CW-10 Microsoft Visual Web Developer 2005 Express Edition: Build a Web Site Now!
10
Click the Next button to display the last wizard page, then click the Finish button to redisplay the
Security tab of the Web Site Administration Tool.
You can rerun the wizard any time but the links at the bottom of the security page
provide a more direct path to specific functions. In addition, the Create Or Manage Roles
link assigns login accounts to roles, a function the wizard doesnt include.
TO ASSIGN LOGIN ACCOUNTS TO ROLES
1

On the Security tab of the Web Site Administration Tool, click the Create Or Manage Roles link.
2
On the resulting page, click the Manage link that appears to the right of the role you want to
configure.
3

When the Web page shown in Figure 17-7 appears, display a list of user names by either:
Using the Search By drop-down list, the For text box, and the Find User button, or
Clicking one of the first initial links (A-Z and All)
4

Select or clear the User Is In Role checkbox for each account as necessary.
5

Click the Back button to select another role or return to the Security page.
Table 17-1
Options for Applying Access Rules
Option Description
Role All users in a given role. Use the drop-down list to select which role.
User A specific user. Enter the user name in the accompanying text box.
All Users All users who have accounts.
Anonymous Users Users who dont have accounts or havent logged in.
C17622124.indd 10 9/11/05 4:53:54 PM
Chapter 17: Controlling Access to Your Site CW-11
Adding Login Controls to Your Site
Once youve configured the security settings and access rules for your site, youll need to
create Web pages that visitors can use to login, change their password from time to time,
recover a forgotten password, or even (if you decide to permit it) self-register.
ASP.NET 2.0 includes a set of Web server controls that make creating these pages very
easy. To use these controls in Visual Web Developer, just drag the one you want from the
Toolboxs Login group and drop it on an open ASP.NET Web page. Table 17-2 lists these
controls.
Toollbox Name Tag Name
Figure 17-7
This Web page controls which login accounts
belong to a given role.
C17622124.indd 11 9/11/05 4:53:55 PM
CW-12 Microsoft Visual Web Developer 2005 Express Edition: Build a Web Site Now!
A site that requires logging in should always contain these two pages:
login.aspx When an anonymous visitor requests a secure page, ASP.NET will automati-
cally redirect the request to a page named login.aspx located in the sites root folder. The
Login link that a LoginStatus control displays also points to login.aspx. If your site doesnt
contain a login.aspx page, your visitors will get a 404 Not Found error instead of a login
prompt.
Table 17-2
ASP.NET 2.0 Login Controls
Toolbox Name Tag Name Description
Login <asp:login> Displays a standard login form.
LoginView <asp:loginview> Displays one of several custom login
forms based on the visitors current
login status: anonymous, logged-in,
logged-in and member of a certain role,
and so forth. The Web developer has to
design and configure these templates.
CreateUserWizard <asp:CreateUserWizard> Displays a form that creates new login
accounts.
ChangePassword <asp:ChangePassword> Displays a form that changes a login
accounts password.
PasswordRecovery <asp:passwordrecovery> Displays a form that resets a visitors
password and sends it to the visitor
by e-mail.
LoginName <asp:loginname> If the current visitor is logged in,
displays the login name. Otherwise
displays nothing.
LoginStatus <asp:loginstatus> Displays a Login link if the current visitor
is anonymous. Displays a Logout link if
the visitor is logged in.
C17622124.indd 12 9/11/05 4:53:55 PM
Chapter 17: Controlling Access to Your Site CW-13
default.aspx If a visitor requests a page but lacks permission to display it, ASP.NET will
redirect the visitor to the sites login.aspx page. Then, if the login succeeds, ASP.NET redirects
the visitor to the secure page he or she originally requested.
If, however, the visitor follows a hyperlink or Favorites entry to the login.aspx page, and if the
login is successful, ASP.NET redirects the visitor to the sites home page: default.aspx in the sites
root folder. This is one of many good reasons to name your sites home page default.aspx.
Figure 17-8 shows a login page for the Contoso Magic Web site. This page uses three
controls from the Login group:
A Login form in the center of the page. After dragging this control from the Toolbox and
dropping it onto the page, the only change was a CssClass attribute that provides the
colored background and the dotted border. The tag for this control is:
<asp:Login ID=Login1 runat=server CssClass=formbox />
Chapter 10 explained how to create CSS classes like formbox.
A LoginStatus control just below the breadcrumb trail. By adding this control to the sites
master page, the developer added a Login/Logout link to every page. All settings are the
default values. The tag is:
<asp:LoginStatus ID=LoginStatus1 runat=server />
A LoginName control at the right, under the date message, displays the text You Are
Logged In As: and the current login name (if any). The tag is:
<asp:LoginName ID=LoginName1 runat=server
FormatString=You are logged in as: {0}. />
The LoginName control displays the contents of the FormatString attribute only when
the current visitor is logged in. In the usual ASP.NET way, it replaces {0} with the first (and
in this case only) available parameter: the current username. If no one is logged in, the
control displays nothing.
Like the LoginStatus control, this LoginStatus control appears in the sample sites master
page. This, however, isnt a requirement. You can add either of these controls to any
page, user control, custom control, or master page you want.
C17622124.indd 13 9/11/05 4:53:56 PM
CW-14 Microsoft Visual Web Developer 2005 Express Edition: Build a Web Site Now!
LoginStatus Control
Login Control
LoginName Control
Figure 17-9 shows the forms that the CreateUserWizard, ChangePassword, and
PasswordRecovery controls display by default. A CSS class provides the background color and
the dotted border. To use these controls, simply drag them onto a Web page, save the page,
and then add it to your menu system. In the sample site, these pages and the login page are
all under a main menu item named Security.
Figure 17-8
This is the login form for the Contoso
Magic site. A Login Web server con-
trol with default settings (except for a
CSS class) provides the login form.
Everything else comes from a master
page.
C17622124.indd 14 9/11/05 4:53:57 PM
Chapter 17: Controlling Access to Your Site CW-15
For simplicity, this section
showed how to use the various
Login controls with most or
all defaults in effect. In fact,
however, these controls are
highly configurable. They provide
dozens of properties, methods,
and events. Whatever you want to
changesuch as colors, fonts, on-
screen titles, error messages, field
editing, or visibility under various
conditionsyou can probably find
a property that does what you want. If you cant find the property you need in the
Properties window, display the controls Help page.
Hiding Menu Options for Secured Pages
For many sites, it makes perfect sense that if a visitor can access a certain page, that page
ought to appear in the sites menu system. Conversely, if a visitor cant access a certain page,
that page should be absent from the sites menu system.
Logical as this might seem, its not the default ASP.NET behavior. If you want menu
options to appear and disappear in sync with the current visitors permissions, you need to
perform two tasks.
Add roles attributes to your web.sitemap file.
Set the securityTrimmingEnabled property of the XmlSiteMapProviderObject to true. This
requires copying 10 lines of fairly messy XML code from the sample files and pasting
them into your web.config file.
The procedure for adding roles attributes to your web.sitemap file is fairly simple.
Figure 17-9
These forms come from CreateUserWizard,
ChangePassword, and PasswordRecovery Web
server controls.
C17622124.indd 15 9/11/05 4:53:58 PM
CW-16 Microsoft Visual Web Developer 2005 Express Edition: Build a Web Site Now!
TO ADD ROLES ATTRIBUTES TO YOUR WEB.SITEMAP FILE
1

Open your site in Visual Web Developer, then open the web.sitemap file.
2
For each menu option (that is, each siteMapNode tag) that should appear only for visitors in a certain
role, add a roles attribute like the one shown below in green.
<siteMapNode url= title=Product Updates
description=Update the Products Database
roles=Administrator >
</siteMapNode>
If the menu item should appear for visitors in more than one role, specify a list of roles separated by com-
mas, such as
roles=friends,romans,countrymen
3
Add the following roles attribute to each remaining menu option at the same level. The asterisk role
(*) means everybody.
roles=*
4

Save the web.sitemap file and test the site.
At this point, you should notice that blocked menu items are still visible.
TO MAKE BLOCKED MENU ITEMS DISAPPEAR
1

Open your site in Visual Web Developer, then open the web.config file.
2
Add the following lines of XML code either just after the <system.web> tag or just before the
</system.web> tag. (The line breaks on line 6 are for readability.)
C17622124.indd 16 9/11/05 4:53:58 PM
Chapter 17: Controlling Access to Your Site CW-17
01 <siteMap defaultProvider=XmlSiteMapProvider enabled=true>
02 <providers>
03 <clear />
04 <add name=XmlSiteMapProvider
05 description=SiteMap provider which reads in .sitemap XML files.
06 type=System.Web.XmlSiteMapProvider, System.Web,
Version=2.0.0.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a
07 siteMapFile=web.sitemap
08 securityTrimmingEnabled=true />
09 </providers>
10 </siteMap>
This block of code appears in the web.config file for the ContosoMagic17 sample site. To save typing, you
may wish to open that file, copy the block of code, and paste it into your own web.config file.
3

Save the web.sitemap file and test the site.
The important part of this code appears on line 8, which activates a feature named
securityTrimmingEnabled. Unfortunately, the XmlSiteMapProvider object can only enable
or disable this feature when it initially loads. Therefore, the <clear /> tag on line 3 unloads
any existing site map providers and the <add> tag beginning on line 4 reloads the
XmlSiteMapProvider object with securityTrimmingEnabled in effect.
Publishing Security Settings
Physically, the security settings this chapter explains reside in two places: the sites
web.config file and its AspNetSqlProvider database. This database resides in the sites
App_Data folder and its file name is ASPNETDB.MDF.
C17622124.indd 17 9/11/05 4:53:58 PM
CW-18 Microsoft Visual Web Developer 2005 Express Edition: Build a Web Site Now!
When you publish a site for the first time, you can publish these files right along with
everything else. Then, if your site is fully ASP.NET 2.0 compliant, your security settings should
take effect immediately. Of course, the usual precautions about publishing web.config files
and databases remain in effect. As the previous chapter explained, they may require some
adjustment depending on your providers configuration.
On an ongoing basis, the security settings (and certainly the user databases) of the two
sites will almost certainly diverge. As a result, youll probably need to administer the security
settings on your production site separately from any working copies.
In Summary
ASP.NET 2.0 provides powerfulyet easy-to-use featuresfor controlling access to a
Web site. You can use either Windows login accounts or custom accounts stored in a SQL
Server database to authenticate visitors to your site. Similarly, if you choose to use roles,
these can be either Windows security groups or custom roles stored in SQL Server.
ASP.NET 2.0 also provides Web server controls that display login, change password,
recover password, and create user forms. By using these controls, you can create Web pages
that provide the corresponding functions with very little effort.
Controlling access to pages and controlling the visibility of menu items are two separate
tasks. To control the visibility of menu items, you have to add roles attributes to your web.
sitemap file and add a few lines of XML to your web.config file.
Although you can initially publish security settings from a working copy of your site to
a production copy, this usually isnt practical over time. Copying the sites security database,
for example, would overwrite the target sites list of login accounts and passwords. Instead,
you should administer the security settings for each site separately.
The next chapter will explain how to use Web Parts in an ASP.NET 2.0 site. Web Parts
are special server controls that administrators and visitors, subject to security, can add,
rearrange, remove, and configure themselves using only a browser.
C17622124.indd 18 9/11/05 4:53:59 PM
CW-19
Introducing Web Part
Controls and Terms, 202
Creating Your Own Web
Part Page, 207
Chapter 18
Displaying
Web Parts
18
ASP.NET server controls provide tremendous flexibility, productivity, and ease
of use for Web developers, but no special flexibility for Web visitorsunless,
that is, the server controls are Web Parts.
Like other kinds of server controls, Web Parts are independent software
components that execute on the Web server as part of a complete Web
page. As with Web user controls and Web custom controls, you can develop
Web Parts once and use them in many different pages and many different
contexts. The key advantage of Web Parts is that Web visitors, subject to
limitations you set, can show, hide, configure, and rearrange Web Parts any
way they like.
Prior to ASP.NET 2.0, Web Parts required special programming and
worked only in Microsoft Windows

SharePoint

Services. Now, however,


any server control can be a Web Part, and any ASP.NET Web page can
display one. This chapter will explain how you can easily use Web Parts on
your own site.
A word of warning: using Web Parts to their fullest does require writing a
small amount of program code.
C18622124.indd 19 9/11/05 4:55:42 PM
CW-20 Microsoft Visual Web Developer 2005 Express Edition: Build a Web Site Now!
Introducing Web Part Controls and Terms
Any page that displays a Web Part must be an ASP.NET 2.0 page (with an .aspx filename
extension) and must contain a WebPartManager control. This control displays no output of
its own, but it coordinates many Web Part features. Physically, it must appear before any
other Web Part controls on the same page.
A WebPartZone control encloses an area where Web Parts can appear. Any page that
contains a WebPartManager control can contain any number of zones.
Web Parts are special server controls that reside within Web Part zones. Web Parts
normally require special programming but ASP.NET 2.0 provides a GenericWebPart control
that can display any server control as a Web Part.
The page shown in Figure 18-1 illustrates these concepts. The following points are
important:
Because Web Part features are working, a WebPartManager control must be present,
even though it displays nothing of its own.
There are two Web Part zones: one titled Left Sleeve and one titled Right Sleeve.
The Left Sleeve zone contains three Web Parts named Cards, Cell Phone, and Dove.
The Right Sleeve zone contains three Web Parts named Watch, Rabbit, and Keys.
The visitor has already clicked the drop-down arrow for the Dove Web Part and selected
Minimize. As a result, only the Web Parts title bar appears.
The visitor has now clicked the drop-down arrow for the Rabbit Web Part. This displays a
popup menu with these choices:
Minimize makes the Web Part display only its title bar.
Close completely removes the Web Part from view.
Any page that contains Web Parts
is a Web Part Page.
NOT E
The sample pages for this chapter
reside in the ContosoMagic17 Web
site. To create your own account
for logging in, open the site in
Microsoft Visual Web Developer,
choose ASP.NET Configuration
from the Website menu, then click
Security and Create Users. To use
an account that comes with the
sample files, specify UserName:
visitor and Password: vwd$2005.
T I P
C18622124.indd 20 9/11/05 4:55:43 PM
Chapter 18: Displaying Web Parts CW-21
If a visitor hasnt logged in, he or she can only see Web
Parts in their default state. That is, Web Parts appear with
the visibility, position, and maximized/minimized state that
the Web developer specified when designing the page.
In order to minimize, restore, close, or otherwise modify
Web Parts, visitors must first log in as Chapter 17 described.
This is because ASP.NET stores each visitors Web Part
settings in that visitors profile. (An ASP.NET 2.0 profile is a
block of data within each login account that stores visitor
preferences.) This has two benefits:
Web Part preferences persist across logins, regardless of
time interval. As long as the login account exists, so will
the saved Web Part preferences.
Each visitor has his or her own set of Web Part prefer-
ences. When a visitor reconfigures a Web Part it doesnt
affect any other visitors view of that Web Part or the
Web Part Page that contains it.
Figure 18-1
The six objects that appear horizontally on
this page are Web Parts that visitors can
configure to suit their needs and interests.
No dove picture appears because the visitor
minimized that Web Part.
C18622124.indd 21 9/11/05 4:55:44 PM
CW-22 Microsoft Visual Web Developer 2005 Express Edition: Build a Web Site Now!
At any given moment, a WebPartManager control (and therefore all Web Parts on the
same page) can be in any of four modes. These are:
Browse Visitors can minimize, restore, or close any Web Part on the page. They do this
by clicking the drop-down arrow that appears in the top right corner of any Web Part
and then choosing the command they want. Figure 18-1 shows this mode in effect.
Design Visitors have all the capabilities of Browse mode, plus the ability to rearrange
Web Parts within or across any zones in the same page. They do this by dragging the
Web Parts title bar and dropping it where they want it. Figure 18-2 shows a visitor drag-
ging the Watch Web Part out of the Right Sleeve zone and dropping it into the Left
Sleeve zone.
Figure 18-2
Visitors who invoke Design mode can
rearrange any Web Parts the page
contains. ASP.NET stores such changes
in the visitors profile and saves them
from session to session.
Closing a Web Part removes it
from memory, and from view. To
restore a closed Web Part, the visi-
tor must enter Catalog mode.
NOT E
C18622124.indd 22 9/11/05 4:55:46 PM
Chapter 18: Displaying Web Parts CW-23
Edit Visitors have all the capabilities of Browse and Design modes plus an additional
command named Edit on the drop-down menu for each Web Part. Choosing this option
displays an Editor Zone like the one shown at the right in Figure 18-3. Visitors can make
any changes they want, then click the OK button or the Apply button to save them.
To quit without saving, the visitor clicks the Cancel button at the bottom of the zone or
the Close link in the top right corner.
Figure 18-3
Pages in Edit mode display an Edit Zone
where visitors can customize aspects of
individual Web Parts.
A Web Parts Chrome Type refers
to the style of its title bar and
border (i.e. to its trim). A Web
Parts Direction refers to its lin-
guistic direction. In English and
Spanish, for example, words and
letters appear from left to right. In
Hebrew and Arabic, the words and
letters appear from right to left.
T I P
C18622124.indd 23 9/11/05 4:55:47 PM
CW-24 Microsoft Visual Web Developer 2005 Express Edition: Build a Web Site Now!
Catalog Visitors have all the capabilities of Browse and Design modes. In addition, the
page displays a Catalog Zone like the one at the right in Figure 18-4. This zone displays
check boxes for any Web Parts that the developer includes on the page, but that the visi-
tor subsequently closes (by opening the popup menu and choosing Close).
To restore a closed Web Part, the visitor selects its check box in the Catalog Zone, selects
a zone in the Add-To drop-down list, and then clicks the Add button. If necessary, the
visitor then switches to Design mode and moves the newly-visible Web Part into place.
Figure 18-4
In Catalog mode, a Web Part Page
displays a Catalog Zone that lists Web
Parts no longer on display, and pro-
vides a means of restoring them.
C18622124.indd 24 9/11/05 4:55:48 PM
Chapter 18: Displaying Web Parts CW-25
Web Parts can, of course, do far more than display pictures of magical props. In one
common scenario, the catalog zone for a corporate home page offers dozens or hundreds
of Web Parts, each with its own specialty: corporate news feeds, industry news feeds, stock
prices, corporate metrics, and many other choices. Each employee then configures the home
page to display the information that interests or concerns him or her the most.
Creating Your Own Web Part Page
Preparing the Sleeve Trick page (tricks/sleeves.aspx in the ContosoMagic17 sample files) isnt
difficult but it does involve some repetitive work and a bit of program code that ties the var-
ious components together. The next few sections explain, in a general way, how to create
this Web Part Page.
Gathering Web Parts
Constructing a Web Part Page is rather pointless unless you have some Web Parts to display.
You can buy purchase Web Parts commercially or ask your IT department to program Web
Parts, but in most cases the fastest and easiest way of obtaining Web Parts is to write them
yourself as Web user controls.
The Web Parts in the Sleeve Trick page are all very simple Web User controls. Here, for
example, is the complete source code listing for the cards.ascx control (using C# syntax):
01 <%@ Control Language=C# ClassName=cards %>
02 <script runat=server>
03 protected void Page_Init(control sender, EventArgs e)
04 {
05 GenericWebPart gwp = Parent as GenericWebPart;
06 if (gwp != null)
07 {
08 gwp.Title = Cards;
09 gwp.TitleIconImageUrl = ../images/haticon.gif;
If youve forgotten how to cre-
ate Web user controls, refer to
Chapter 8, Creating and Using
Web User Controls.
MORE I NF O
C18622124.indd 25 9/11/05 4:55:49 PM
CW-26 Microsoft Visual Web Developer 2005 Express Edition: Build a Web Site Now!
10 gwp.CatalogIconImageUrl = ../images/haticon.gif;
11 }
12 }
13 </script>
14 <img border=0 src=../images/cards.gif />
Here are the important features of this code:
The @ Control directive on line 1 specifies options for the user control. The program-
ming language will be C# and compiling the control will create a class (a type of object)
named cards.
The <img > tag that appears on line 14 displays the picture of a deck of cards.
The statements on lines 1 and 14 are all the statements you really need. However, the
resulting Web Part would display the word Untitled in its title bar, and would contain no
icons in its title bar or in Catalog mode. The code on lines 2 through 13 corrects these visual
shortcomings. Heres a brief explanation of this code:
The tags on lines 2 and 13 mark the beginning and end of some program code that will
run on the Web server.
Line 3 defines a function named Page_Init. Because it has this name, ASP.NET will run it
automatically when ASP.NET initializes the rest of the Web page. The function parameters
sender and e satisfy ASP.NET requirements.
The curly braces ({ }) on lines 4 and 12 mark the beginning and end of the Page_Init
functions source code.
Line 5 is more complex. When you use a Web user control as a Web Part, ASP.NET loads
a GenericWebPart control and tells that control to load the Web user control you want.
In that situation, the statement on line 5:
GenericWebPart gwp = Parent as GenericWebPart;
establishes the variable gwp as a pointer to the parent GenericWebPart control.
C18622124.indd 26 9/11/05 4:55:49 PM
Chapter 18: Displaying Web Parts CW-27
If, however, youre using the same Web user control in an ordinary ASP.NET Web page,
the controls parent wont be a GenericWebPart control; it will most likely be a Page
control or another Web user control. Because it cant make the gwp variable point to a
GenericWebPart control, ASP.NET will set the variable to null.
Line 6 determines whether the gwp variable contains something other than null. If so:
Line 8 sets the GenericWebPart controls Title property.
Line 9 sets the GenericWebPart controls TitleIconImageUrl property so it points to the
icon that should appear in the Web Parts title bar.
Line 10 sets the GenericWebPart controls CatalogIconImageUrl property so it points
to the icon that should identify the Web Part in Catalog mode.
All six controls that the Sleeve Trick example uses as Web Parts follow the same pattern.
To avoid confusion with image URL paths, all six user controls and the Sleeve Tricks Web
page itself will reside in the same folder: tricks.
Creating a Blank Web Part Page
The process for creating a Web Part Page is the same as for creating any other ASP.NET page.
TO CREATE A WEB PART PAGE
1

Right-click the tricks folder and select Add New Item.
2
Select the Web Form template, then specify the other options as you like. The example uses Name:
sleeves.aspx, Language: C#, Place Code In Separate File: cleared, and Select Master Page: checked.
The page also uses the same master page as the rest of the site.
3
Drag a WebPartManager control from the WebParts group of the Toolbox and drop it onto the body
of the Web page. Then, set its ID to wpmSleeves.
C18622124.indd 27 9/11/05 4:55:50 PM
CW-28 Microsoft Visual Web Developer 2005 Express Edition: Build a Web Site Now!
Adding Web Part Zones
When they get to the browser, Web Part Zones are DIVs. As such, they normally cause a line
break and then appear flush left. The usual way of overriding this behavior is by placing the
Web Part Zones in table cells.
TO ADD WEB PART ZONES
1
Add a one-row, three-column HTML table below the WebPartManager control. Make sure this table
appears physically after the WebPartManager control you added in the previous section.
2

Add a two-row, three-column HTML table inside the left cell of the table you created in step 1.
3
Type Left Sleeve into the top left cell of the table you created in step 2. Then, type Right Sleeve into
the top-right cell of the same table. Format these cells as headings. (The middle column is only for
spacing.)
4
Drag a WebPartZone control out of the WebParts group of the Toolbox and drop it into the bottom
left cell of the table from step 2. Give this WebPartZone control an ID of Left and set its
LayoutOrientation property to Horizontal.
5
Repeat step 4, this time dragging the WebPartZone control into the bottom right
cell and giving it an ID of Right. Again, set the LayoutOrientation property to Horizontal.
6
Drag three of your Web Parts or Web user controls out of Server Explorer and drop them in the
Left Web Part Zone. Then, drag the rest of your Web Parts or Web user controls into the Right
Web Part Zone.
7
Save the page and browse it. The Web Parts should appear, but unless you log into the site, you
wont be able to modify them from the browser.
8
Log into the site, then try using the drop-down arrows on each Web Part. Initially, the popup menu
options should be Minimize and Close.
C18622124.indd 28 9/11/05 4:55:51 PM
Chapter 18: Displaying Web Parts CW-29
Choosing Minimize should hide the entire Web Part except for its title bar, and should change its popup
menu commands to Restore and Close.
Choosing Close should hide the entire Web Part with no way (for now) of getting it back. The next
section will explain how to modify the page so visitors can restore closed Web Parts.
Adding Editor and Catalog Zones
For Edit mode to work, your page must contain an Editor zone that contains an Editor Web
Part. Similarly, for Catalog mode to work, your page must contain a Catalog zone that con-
tains a Catalog Web Part.
TO ADD EDITOR AND CATALOG ZONES AND WEB PARTS
1
Drag an EditorZone control out of the WebParts group of the Toolbox and drop it into the rightmost
cell of the table you created in step 1 of the previous section.
2
Drag an AppearanceEditorPart control out of the WebParts group of the Toolbox and drop it onto the
EditorZone control from step 1.
3
Drag a CatalogZone control out of the WebParts group of the Toolbox and drop it into the same
cell as the EditorZone control from step 1. (The order doesnt matter. These two controls will never
be visible at the same time.)
4
Drag a PageCatalogPart control out of the WebParts group of the Toolbox and drop it onto the
CatalogZone control from step 3.
If you find that Web Part popup
menus dont appear with the font,
border, colors, and other proper-
ties you want, select the Web Part
Zone, open the MenuPopupStyle
group in the Properties window,
and specify the formatting you
want.
T I P
C18622124.indd 29 9/11/05 4:55:51 PM
CW-30 Microsoft Visual Web Developer 2005 Express Edition: Build a Web Site Now!
Switching Display Modes
To switch your Web Part Page between Browse, Design, Edit, and Catalog modes, you need
to programmatically change the WebPartManager controls DisplayMode property to one of
four values:
WebPartManager.BrowseDisplayMode
WebPartManager.DesignDisplayMode
WebPartManager.EditDisplayMode
WebPartManager.CatalogDisplayMode
The sample page uses a drop-down list to trigger these property changes. To create this
control, proceed as follows.
TO CREATE A DROP-DOWN LIST
1
Drag a DropDownList control out of the Standard group of the Toolbox and drop it onto any conve-
nient spot on the Web page. Give this control an ID of ddlMode.
2
Drag a Literal control out of the Standard group of the Toolbox and drop it near the DropDownList
control from step 1. This control will display any error messages that result from attempting to switch
Web Part modes. Give this control an ID of litMode and set its EnableViewState property to false. (Disabling
view state automatically clears the previous message during each form submission).
3

Select the DropDownList control from step 1, then locate its Items property in the Properties window.
4

Click the word Collection to the right of Items, then click the resulting ellipsis () button.
5

When the ListItem Collection Editor dialog box appears:
Click the Add button, then type Browse in the Text box and 0 in the Value box.
Click the Add button, then type Design in the Text box and 1 in the Value box.
Click the Add button, then type Edit in the Text box and 2 in the Value box.
Click the Add button, then type Catalog in the Text box and 3 in the Value box.
C18622124.indd 30 9/11/05 4:55:52 PM
Chapter 18: Displaying Web Parts CW-31
6

Click the OK button, then switch to Source view and check your work. The code should look like this:
<asp:DropDownList ID=ddlMode runat=server>
<asp:ListItem Value=0>Browse</asp:ListItem>
<asp:ListItem Value=1>Design</asp:ListItem>
<asp:ListItem Value=2>Edit</asp:ListItem>
<asp:ListItem Value=3>Catalog</asp:ListItem>
</asp:DropDownList>
Make any corrections you need, then return to Design view.
7
With the drop-down list still selected, locate its AutoPostBack property in the Properties window. To
cause a form submission every time the visitor selects a different item, set the AutoPostBack property
to True.
8
Double-click the drop-down list. This will switch the display into Source view and display an empty
function that looks like this:
protected void ddlMode_SelectedIndexChanged(control sender, EventArgs e)
{

}
9

Enter the following program code inside the function you created in step 8:
01 try
02 {
03 switch (ddlMode.SelectedValue)
04 {
05 case 1:
06 wpmSleeves.DisplayMode = WebPartManager.DesignDisplayMode;
07 break;
08 case 2:
09 wpmSleeves.DisplayMode = WebPartManager.EditDisplayMode;
C18622124.indd 31 9/11/05 4:55:52 PM
CW-32 Microsoft Visual Web Developer 2005 Express Edition: Build a Web Site Now!
10 break;
11 case 3:
12 wpmSleeves.DisplayMode = WebPartManager.CatalogDisplayMode;
13 break;
14 default:
15 wpmSleeves.DisplayMode = WebPartManager.BrowseDisplayMode;
16 break;
17 }
18 }
19 catch (Exception ex)
20 {
21 litMode.Text = ex.Message;
22 }
23 CheckDisplayMode();
In this code:
A try block starts on lines 1 and 2 and ends on line 18. This captures any exceptions (i.e. serious errors)
that the WebPartManager control might raise. These occur, for example, when a visitor whos not logged
in tries to enter Design, Edit, or Catalog mode.
A switch block starts on lines 3 and 4 and ends on line 17. This block tests the current selection in the
ddlMode drop-down list box and sets the DisplayMode property of the WebPartManager control named
wpmSleves accordingly.
The catch block on lines 19 through 22 immediately follows the try block, and runs only if the try block
detects an exception. This block receives an Exception object named ex and displays that objects
Message property in the Literal control named litMode. You created this control in step 2.
The CheckDisplayMode() statement on line 23 runs a function that queries the WebPartManager con-
trols DisplayMode property and resets the ddlMode drop-down list accordingly. This is necessary
because when change of mode fails, the WebPartManager and the drop-down list will be out of sync.
The next step will explain how to write this function.
C18622124.indd 32 9/11/05 4:55:53 PM
Chapter 18: Displaying Web Parts CW-33
10
Add the following function after the code from steps 8 and 9 and just before the </script> that
follows it.
01 private void CheckDisplayMode()
02 {
03 if (wpmSleeves.DisplayMode == WebPartManager.BrowseDisplayMode)
04 {
05 ddlMode.SelectedIndex = 0;
06 return;
07 }
08 if (wpmSleeves.DisplayMode == WebPartManager.DesignDisplayMode)
09 {
09 ddlMode.SelectedIndex = 1;
10 return;
11 }
12 if (wpmSleeves.DisplayMode == WebPartManager.EditDisplayMode)
13 {
14 ddlMode.SelectedIndex = 2;
15 return;
16 }
17 if (wpmSleeves.DisplayMode == WebPartManager.CatalogDisplayMode)
18 {
19 ddlMode.SelectedIndex = 3;
20 };
21 }
This is the function that line 23 from step 9 calls. Lines 3 through 7 determine if the WebPartManager con-
trol wpmSleeves is in Display mode and if so, it makes sure that the first item (index 0) in the drop-down
list, ddlMode, is selected. Lines 8 through 11 determine if the WebPartManager control is in Design mode,
and so forth.
C18622124.indd 33 9/11/05 4:55:53 PM
CW-34 Microsoft Visual Web Developer 2005 Express Edition: Build a Web Site Now!
11
Note that the WebPartManager control might change mode for reasons other than the Web visitor
changing the drop-down list box. Suppose, for example, that the page is in Edit or Catalog mode. If
the visitor clicks the Close button in the AppearanceEditorPart or PageCatalogPart control (whichever is visi-
ble), the WebPartManager control will revert to Browse mode, and the ddlMode drop-down list should
revert to Browse as well. To make this happen, proceed as follows:
Return to Design mode in Visual Web Developer.
Select the WebPartManager control.
In the Properties window, click the Events button (the lightning bolt icon).
In the resulting list of events, double-click DisplayModeChanged.
This will switch Visual Web Developer to Source mode and add the lines shown below in normal weight.
Add the line shown in green.
protected void wpmSleeves_DisplayModeChanged(control sender,
WebPartDisplayModeEventArgs e)
{
CheckDisplayMode();
}
Now, whenever the WebPartManager controls DisplayMode property changes, this function will run the
CheckDisplayMode function from step 10. That function, of course, synchronizes the drop-down list to the
current DisplayMode.
This completes the coding for the Sleeve Trick page. Once this page is working, you can
add it to the web.sitemap file just as you did for any other page in the site.
By now, you should know how you keep visitors from adding unauthorized Web Parts to
a page: Dont add those Web Parts when you develop the page. The only Web Parts visitors
can add are those you include when you develop a page.
Similarly, its easy to keep visitors from using display modes you dont want them to
access: Avoid writing any program code that switches to those modes.
C18622124.indd 34 9/11/05 4:55:54 PM
Chapter 18: Displaying Web Parts CW-35
In Summary
Web Parts are independent units of content that, like any other server control, you can
include in many different Web pages. Web Parts, however, have special capabilities so that
each visitor can add, configure, rearrange, or hide any Web Part the developer provides. In
this way, visitors can customize the site to their own needs and preferences.
Any ASP.NET page that contains Web Parts is a Web Part Page. Each Web Part Page
must contain one WebPartManager control and at least one WebPartZone control. The
WebPartZone controls contain the Web Parts.
WebPartManager controls (and therefore Web Part Pages) support four display modes:
Browse (which can minimize, restore, and close Web Parts); Design (which can also rearrange
Web Parts); Edit (which can also modify Web Part properties); and Catalog (which can
reinstate closed Web Parts). Letting visitors switch among these modes requires writing a
small amount of program code.
Visual Web Developer 2005 Express Edition is a powerful, sophisticated, yet easy-to use
development environment for Web pages. It supports a wide range of todays best and
newest Web techniques including WYSIWYG editing, site management, cascading style
sheets, drop-down or fly-out menus, site maps, breadcrumbs, database integration, login
security, and visitor customization. It takes full advantage of ASP.NET 2.0 and Microsoft SQL
Server, both of which are widely available at a reasonable cost.
Of course, no piece of software can create Web sites on its own. The concept, the
design, the structure, and the hard work are still yours to contribute. Hopefully, Visual Web
Developer will provide the best possible channel between your thoughts, your efforts, and
extraordinary results. Good luck with your site and I hope we meet again.
C18622124.indd 35 9/11/05 4:55:54 PM
C18622124.indd 36 9/11/05 4:55:54 PM
<aWXk
&-,
4
absoluLe posiLioning, 64-65
access. See also securiLy
daLabases, 88
AccessDaLaSource daLa source conLrol, 5
accounLs
SOL Server, 85
Windows AccounLs, 84-85
Add ConnecLion dialog box, 89-4
Add New lLem dialog box, 86, 7
Add New lLem page, 52-58
Add SLyle Rule command (SLyles menu), 0
Add SLyle Rule dialog box, 0
Add WHFRF Clause dialog box
adminisLraLion
daLabase access, 88
shared SOL Servers, 82
Advanced command (FdiL menu), 82
Advanced seLLing (SelecL SLaLemenL dialog box),
58
Anonymous Login ield (Choose LocaLion dialog
box), 88
App_DaLa older, 42
copy SOL Server daLabases, 74-75
copying, 48
applicaLions
llS, 24
masLer pages, 08-06
looking inside masLer pages, 04
modicaLion o exisLing pages, 04-05
modicaLion o header inormaLion, 06
relaLive URLs, 06
MicrosoL visual Web Developer 2005 Fxpress
FdiLion, 8-4
user conLrols, 90-98
coding aLLribuLes, 92-98
CSS sLyles, 9
relaLive URLs, 9-92
Lags, 90
visual Web Developer 2005 Fxpress
FdiLion, 8-4
Web user conLrols, CSS sLyles, 9
arbiLrary Web siLes, opening, 87-48
ASP.NF1 2.0
daLa ormaL sLrings, 6-62
eaLures, -2
LiLeral conLrols, 0
programming model, 8
resources, 8
server conLrols, 4-6, 20
Lhemes, 5-28
adding CSS sLyle sheeLs, 9-20
adding skins, 6-9
applying Lo Web pages and siLes, 20-28
creaLing, 6
Web page delivery, 4-9
evenLs, 8-9
hierarchy o conLrols, 6-7
page lie cycle, 9
Web siLe hyperlinks
breadcrumbs, 84-86
drop-down menus, 8-88
y-ouL menus, 8-88
siLe map les, 26-80
1ree view menus, 88-84
ASP.NF1 DevelopmenL Server, 24
ASP.NF1 Web MaLrix, 5
ALLachDbFilename, FxLended ProperLies, lniLial
File Name parameLer, 80
ALLachDbFileName connecLion sLring, 84
aLLaching daLabase iles, 84
aLLribuLes, coding, Web user conLrols, 92-98
AuLo FormaL command (conLrol shorLcuL
menus), 68
AuLoCeneraLelnserL8uLLon properLy (DeLailsview
conLrol), 70
AuLoCeneraLeRows properLy (DeLailsview
conLrol), 70
AuLoPosL8ack="1rue" aLLribuLe (server
conLrols), 22
5
bannerLxL CSS rule, 99
8ookmark All command (Find and Replace
command), 78
bookmarks, source code LexL ediLor, 72
8ookmarks command (FdiL menu), 72
borderLexL CSS rule, 00
borderLxL CSS rule, 98
8oundField properLies, 6
breadcrumbs, linking Web siLe pages, 84-86
8uild menu commands, 8uild Web SiLe, 88
8uild Web SiLe command (8uild menu), 88
6
C#, resources, 8
Cascading SLyle SheeLs. See CSS
caLegorizaLion, server conLrols, 20
Web cusLom conLrols, 20-2
Web user conLrols, 20
CaLegoryld ield (ProducLs Lable), 45
cenLralized page layouL, masLer pages, 95-96
Change DaLa Source dialog box, 89
child insLances. See user insLances
Choose DaLa Source dialog box, 89
Choose DaLa Source opLion, 69
Choose LocaLion dialog box, 28-29
Choose Name dialog box, 45
Choose our DaLa ConnecLion dialog box,
5-52
Class SelecLor (CSS sLyle names), 0
Code 8ehind progam code sLorage, 82
code compleLion. See lnLelliSense
X1146481Z01.indd 187 9/14/05 10:07:27 AM
&-- B^Xgdhd[iK^hjVaLZW9ZkZadeZg'%%*:megZhh:Y^i^dc/7j^aYVLZWH^iZCdl
CodeFile aLLribuLe (@ Page direcLive), 88
coding, aLLribuLes, Web user conLrols, 92-98
Column value
(Add WHFRF Clause dialog box), 58
Columns seLLing
(SelecL SLaLemenL dialog box), 52
commands
8uild menu, 8uild Web SiLe, 88
FdiL menu
Advanced, 82
8ookmarks, 72
Find and Replace, 77
Co 1o, 72
lnLelliSense, 75
ediLing, source code LexL ediLor, 82
File menu
New File, 52, 86
Open File, 58
Open Web SiLe, 87
RecenL Files, 58
RecenL ProjecLs, 86
FormaL menu
ConverL Lo Hyperlink, 66
SLyle, 64, 08
LayouL menu, 64
lnserL 1able, 57
SLyles menu, Add SLyle Rule, 0
1ools menu, OpLions, 69
view menu
DocumenL OuLline, 60
1oolbars, H1ML Source FdiLing, 77
Web siLe menu, Copy Web SiLe, 46
Window menu
Remove SpliL, 7
SpliL, 7
compiling program code, 88
coniguraLion
daLa sources, 5-55
daLabase access, 88
Cridview conLrol, 57-6
Cridview conLrol, updaLes, 67-68
connecLion sLrings, 77-79
ALLachDbFileName, 84
parameLers, 79, 8
connecLions, daLabases, 87
coniguraLion, 88
connecLing Lo exisLing daLabases, 88-89
conLenL
ASP.NF1 server conLrols, 4-6
H1ML Lags, 4
conLenL pages, 96
applying masLer pages Lo, 00-02
ConLenL server conLrol, 02
ConLenLPlaceHolder conLrol, 97-98
ConLenLPlaceHolderlD= aLLribuLe, 05
ConLoso Magic CosLumes page,
creaLing, 57-6
ConLosoMagic daLabase
adding Lo sample siLe, 42
Lables, ProducLs, 48-45
conLrols
adding Lo Web pages, 54-58
rom SoluLion Fxplorer, 57-58
rom Lhe 1oolbox, 54-57
ASP.NF1 LiLeral conLrols, 0
ConLenLPlaceHolder, 97-98
daLa-bound
DaLaLisL, 56
DeLailsview, 56
DropDownLisL, 55-56
Formview, 56
Cridview, 56-6
RepeaLer, 56
daLa sources
AccessDaLaSource, 5
ObjecLDaLaSource, 5
SiLeMapDaLaSource, 5
SqlDaLaSource, 5
XmlDaLaSource, 5
DeLailsview
adding records, 69-7
properLies, 70
double binding, 67-68
Formview, 69
Cridview
conguring, 67-68
creaLing Cridview Web page, 58-59
daLa sources, 50
deleLing records, 66
updaLing records, 66
liL8anner1iLle, 99
Login, 0
seLLing properLies
FormaL menu, 68-64
mouse, 6-68
ProperLies window, 58-6
smarL Lags, 68
Loolbars, 64-65
SiLeMapDaLaSource, 0
SiLeMapPaLh, 0, 84-86
1ree view, 84
UserName, 0
Web page delivery, 6-7
ConLrols collecLion (server conLrols), 6
ConverL Lo Hyperlink buLLon
(FormaLLing Loolbar), 66
ConverL Lo Hyperlink command
(FormaL menu), 66
Copy SelecLed Files command (Copy Web dialog
box, older shorLcuL menus), 47
Copy SiLe Lo RemoLe (or Source) command (Copy
Web dialog box, older shorLcuL menus), 48
Copy Web SiLe command (Web siLe menu), 46
Copy Web window, 46
copying
SOL Server daLabases, 74-75
Web siLes, 45-49
le selecLion, 47-49
speciying source and remoLe Web
siLes, 46-47
CreaLe New SOL Server DaLabase dialog box, 48
CriLeria pane, 47
CSS (Cascading SLyle SheeLs), 07-4
ormaLLing page elemenLs individually, 08
shared sLyle sheeL iles, 09-4
adding properLies, 2
applying Lo Web pages, 8-4
creaLing new les, 09
creaLing sLyle sheeL rules, 09-2
shared sLyle sheeLs, adding Lhemes, 9-20
Web user conLrols, 9
CssClass properLy (DeLailsview conLrol), 70
cusLom conLrols, 20
cusLomizaLion, Web siLes,
X1146481Z01.indd 188 9/14/05 10:07:27 AM
>cYZm &-.
7
Daemon1ools, 7
daLa connecLions, 49
DaLa conLrol group (1oolbox), 56
DaLa older, 42
creaLing daLabases in, 48
daLa ormaL sLrings, ASP.NF1, 6-62
DaLa Source parameLer (connecLion sLrings), 79
daLa sources, 49, 50-5
coniguring, 5-55
conLrols
AccessDaLaSource, 5
ObjecLDaLaSource, 5
SiLeMapDaLaSource, 5
SqlDaLaSource, 5
XmlDaLaSource, 5
Cridview, 50
DaLabase, lniLial CaLalog parameLer, 80
daLabase drivers, 76-77
DaLabase Fxplorer, 9
daLabases
adminisLraLion, access, 88
aLLaching iles, 84
connecLing Lo, 87
conguraLion, 88
connecLing Lo exisLing daLabases, 88-89
ConLosoMagic, adding Lo sample siLe, 42
ConLosoMagic daLabase, ProducLs
Lable, 48-45
creaLing, 87, 42-48
adding ConLosoMagic Lo sample siLe, 42
in deaulL DaLa older, 48
displaying inormaLion, 49
complex page elemenLs, 62
daLa sources, 50-5
daLa-bound conLrols, 55-56
neLwork, 76
publishing
connecLing Lo SOL Server, 75-79
copying SOL Server daLabases, 74-75
records,
deleLing, 66
updaLing, 66
SOL Server
adding ConLosoMagic Lo sample siLe, 42
conguring Add ConnecLion dialog box
or, 40-4
copying, 74-75
creaLing, 42-48
insLance names, 40
visual SLudio versions, 40-4
Lables
modiying, 48-45
1able Designer, 44
updaLing conLenL, 46-48
viewing conLenL, 46-48
visual SLudio supporL, 40-4
daLa-bound conLrols, 49, 55-56
DaLaLisL, 56
DeLailsview, 56
DropDownLisL, properLies, 55-56
Formview, 56
Cridview, 56-6
RepeaLer, 56
DaLaField properLy, 6
DaLaFormaLSLring properLy, 6
DaLaKeyNames properLy (DeLailsview conLrol),
70
DaLaLisL conLrol, 56
DaLaSource, Server, Address, Addr, NeLwork
Address parameLer, 8
DaLaSourceld properLy (DeLailsview conLrol), 70
DaLaSourcelD properLy (DropDownLisL conLrol),
55
DaLa1exLField properLy (DropDownLisL conLrol),
56
DaLavalueField properLy (DropDownLisL conLrol),
56
dbmsads library, 8
dbmslpc library, 8
dbmsrpc library, 8
dbmssoc library, 8
dbmsspx library, 8
dbnmpnL library, 8
debuggers, 24
declaraLion, Public variables, 92
deaulL skins, 8
DeaulLMode properLy (DeLailsview conLrol), 70
Deine CusLom SLaLemenLs Or SLored Procedures
dialog box, 54
DeleLe command (Copy Web dialog box, older
shorLcuL menus), 48
DeleLe command (LayouL menu), 64
DeleLe opLion, 66
deleLing, records, 66
Design view (Web pages), 58
DeLailsview conLrol, 56
adding records, 69-7
properLies, 70
deLecLion, synLax errors, source code LexL
ediLor, 76-77
DevelopmenL Server (ASP.NF1), 24
Diagram pane, 47
dialog boxes
Add ConnecLion, 89-4
Add New lLem, 86, 7
Add SLyle Rule, 0
Add WHFRF Clause
Change DaLa Source, 89
Choose DaLa Source, 89
Choose LocaLion, 28-29
Choose Name, 45
Choose our DaLa ConnecLion, 5-52
CreaLe New SOL Server DaLabase, 48
Deine CusLom SLaLemenLs Or SLored
Procedures, 54
Find and Replace, 77
Hyperlink, 66
lnserL 1able, 57
New lLem, SiLe Map LemplaLe, 26
New virLual DirecLory, 29
New Web SiLe, 26
Open Web SiLe, 87, 47
OpLions, 86
ProperLies, 42
Search and Replace, 78
SelecL A MasLer Page, 0
SelecL SLaLemenL, 67-68
SLyle 8uilder, 08
SLyle Rule Hierarchy,
1ag Speciic OpLions, 8
1esL Ouery, 54-55
DirecLory ield (Choose LocaLion dialog box), 82
displaying
daLabase inormaLion, 49
complex page elemenLs, 62
X1146481Z01.indd 189 9/14/05 10:07:28 AM
&.% B^Xgdhd[iK^hjVaLZW9ZkZadeZg'%%*:megZhh:Y^i^dc/7j^aYVLZWH^iZCdl
daLa sources, 50-5
displaying, daLabase inormaLion, daLa-bound
conLrols, 55-56
DocumenL OuLline command (view menu), 60
double binding, 67-68
drop-down menus, linking Web siLe
pages, 8-88
DropDownLisL conLrol, properLies, 55-56
DropDownLisL Web server conLrol, 2-22
dynamic menu iLems, 82
8
FdiL lmage command (conLrol shorLcuL
menus), 62
FdiL menu commands
Advanced, 82
8ookmarks, 72
Find and Replace, 77
Co 1o, 72
lnLelliSense, 75
FdiL opLion, 66
FdiL 1emplaLe command (conLrol shorLcuL
menus), 68
ediLing commands, source code LexL ediLor, 82
ediLing modes, Web pages
Design view, 58
Source view, 54
Fnable DeleLing opLion, 68
Fnable FdiLing opLion, 68
Fnable lnserLing opLion, 69
Fnable Paging seLLing, 60
Fnable SelecLion opLion, 68
Fnable SorLing seLLing, 60
evenL handlers, 8
Page_Load, 99
evenLs, Web page delivery, 8-9
exisLing Web siLes, opening, 85
FxLensible Markup Language. See XML
(FxLensible Markup Language)
9
eaLures, ASP.NF1 2.0, -2
ields, ProducLs Lable (ConLosoMagic
daLabase), 45
File menu commands
New File, 52, 86
Open File, 58
Open Web SiLe, 87
RecenL Files, 58
RecenL ProjecLs, 86
ile selecLion, copying Web siLes, 47-49
ile sysLem Web siLes, 25-26
advanLages and drawbacks, 25
opening, 87-88
Find and Replace command (FdiL menu), 77
Find and Replace dialog box, 77
Find ln Files command (Find and Replace
command), 79
Find NexL command (Find and Replace
command), 78, 79
Find Symbol command (Find and Replace
command), 79
inding, LexL, source code LexL ediLor, 77-79
lagging llS applicaLions
FronLPage Server FxLensions, 25
MicrosoL llS Manager adminisLraLive Lool, 25
ly-ouL menus, , 8-88
olders
App_DaLa, 42
copying SOL Server daLabases, 74-75
DaLa, 42
creaLing daLabases in, 48
ooLerLxL CSS rule, 00
FormaL menu, seLLing conLrol properLies, 68-64
FormaL menu commands
ConverL Lo Hyperlink, 66
SLyle, 64, 08
FormaL node (OpLions dialog box, H1ML Lab), 8
ormaLLing
page elemenLs, CSS, 08
source code, LexL ediLor, 80-8
FormaLLing Loolbar
ConverL Lo Hyperlink buLLon, 66
modiiying conLrols, 64
Formview conLrol, 56, 69
FronLPage Server FxLensions, lagging llS
applicaLions, 25
F1P-accessible Web siLes, 25, 8-88
opening, 89-40
uncLions, Public declaraLion, 92
:
Ceneral conLrol group (1oolbox), 56
Ceneral node (OpLions dialog box, H1ML Lab), 8
Co 1o command (FdiL menu), source code LexL
ediLor, 72
Cridview conLrol, 68, 56
coniguring, 57-6, 67-68
creaLing Cridview Web page, 58-59
daLa sources, 50
deleLing records, 66
updaLing records, 66
;
header inormaLion, modiicaLion, masLer
pages, 06
Header1exL properLy, 6
hierarchy o conLrols, Web page delivery, 6-7
HorizonLalAlign properLy (DeLailsview
conLrol), 70
HorizonLalAlign seLLing, 6
HosLers Providing ASP.NF1 page, 5
hosLing providers, 5-6
H1ML (Hyper1exL Markup Language), 2
server conLrols, 20
Lags, 4
H1ML conLrol group (1oolbox), 56
H1ML Source FdiLing Loolbar, 77, 82
HLml1able server conLrol, 7
HLml1ableRow server conLrol, 7
Hyperlink dialog box, 66
hyperlinks
adding Lo Web pages, 65-66
Web siLes, 25-86
breadcrumbs, 84-86
drop-down menus, 8-88
y-ouL menus, 8-88
siLe map les, 26-80
1ree view menus, 88-84
Hyper1exL Markup Language. See H1ML
(Hyper1exL Markup Language)
X1146481Z01.indd 190 9/14/05 10:07:28 AM
>cYZm &.&
<
lCssClass seLLing, 6
lD SelecLor (CSS sLyle names), 0
id= aLLribuLe (server conLrols), 4
llS (lnLerneL lnormaLion Server), 24
aligning applicaLions, 24-25
applicaLions, 24
image iles, lSO image iles, 7-6
lnheriLs aLLribuLe (@ Page direcLive), 88
lniLial CaLalog parameLer (connecLion
sLrings), 79
ln-Line progam code sLorage, 82
lnserL command (LayouL menu), 64
lnserL 1able command (LayouL menu), 57, 64
lnserL 1able dialog box, 57
insLallaLion
MicrosoL visual Web Developer 2005 Fxpress
FdiLion, 6
sample iles, 8
insLances
names, 40, 82
server insLances, 82
user insLances, 88-84
lnLegraLed SecuriLy, 1rusLed_ConnecLion
parameLer, 8
lnLelliSense
coniguring processing, 75
source code LexL ediLor, 78-76
lnLelliSense command (FdiL menu), 75
lnLerneL lnormaLion Server. See llS
lSO image iles, 6-7
lSObusLer, 7
lSORecorder, 7
lLemSLyle
HorizonLalAlign properLy, 6
verLicalAlign properLy, 6
?
Language enLry (Add New lLem page), 52, 86, 97
layers, adding Lo Web pages, 57
LayouL menu commands, 64
lnserL 1able, 57
LayouL Loolbar, modiiying conLrols, 64-65
ld iles, 42
lie cycle, ASP.NF1 pages, 9
linking Web siLe pages, 25-86
breadcrumbs, 84-86
drop-down menus, 8-88
ly-ouL menus, 8-88
siLe map iles, 26-80
1ree view menus, 88-84
liL8anner1iLle conLrol, 99
liL8anner1iLle LiLeral server conLrol, 98
LiLeral conLrols (ASP.NF1), 0
LiLeral server conLrols, liL8anner1iLle, 98
local llS Web siLes, 25, 27-29
opening, 88-89
Login conLrol, 0
Login conLrol group (1oolbox), 56
logins, 84-85
SOL Server AccounLs, 85
Windows AccounLs, 84-85
@
MasLer objecL, 06
masLer pages, , 0
applicaLions, 08-06
looking inside masLer pages, 04
modicaLion o exisLing pages, 04-05
modicaLion o header inormaLion, 06
relaLive URLs, 06
applying Lo conLenL pages, 00-02
cenLralizing page layouL, 95-96
creaLing, 96-00
MasLerPageFile= aLLribuLe, 05
md iles, 42
Menu conLrols
linking Web siLe pages, drop-down/ly-ouL
menus, 8-88
properLies, 82
menus
drop-down, linking Web siLe pages, 8-88
ly-ouL, linking Web siLe pages, 8-88
1ree view, linking Web siLe pages, 88-84
Merge Cells command (LayouL menu), 64
MicrosoL llS Manager adminisLraLive Lool,
lagging llS applicaLions, 25
MicrosoL MSDN 2005 Fxpress FdiLion, 7
MicrosoL SOL Server 2005 Fxpress FdiLion, 7
MicrosoL visual Web Developer 2005 Fxpress
FdiLion
applicaLions, 8-4
ASP.NF1 Lhemes, 5-28
CSS sLyle rules, 07-4
ile sysLem Web siLes, 26
F1P-accessible Web siLes, 82-88
insLallaLion, 6
local llS Web siLes, 28
vs. oLher producLs, 8-4
remoLe llS Web siLes, 80-8
source code, LexL ediLor, 67-82
Miscellaneous node (OpLions dialog box, H1ML
Lab), 8
modiicaLions
header inormaLion, masLer pages, 06
Web pages
adding conLrols, 54-58
adding Lables and layers rom Menu bar, 57
hyperlinks, 65-66
seLLing conLrol properLies, 58-65
mouse, seLLing conLrol properLies, 6-68
A
Name enLry (Add New lLem page), 52, 86, 97
Name seLLing (SelecL SLaLemenL dialog box), 52
named skins, 8
names
insLance, 40
insLances, 82
NavigaLion conLrol group (1oolbox), 56
Nero, 7
neLwork daLabases, 76
neLwork libraries, 8
NeLwork Library, NeL parameLer, 80
New File command (File menu), 52, 86
New lLem dialog box, SiLe Map LemplaLe, 26
New virLual DirecLory dialog box, 29
New Web SiLe dialog box, 26
B
ObjecLDaLaSource daLa source conLrol, 5
OD8C, 77
OnlniL server conLrol evenL, 8
OnLoad server conLrol evenL, 8
X1146481Z01.indd 191 9/14/05 10:07:29 AM
&.' B^Xgdhd[iK^hjVaLZW9ZkZadeZg'%%*:megZhh:Y^i^dc/7j^aYVLZWH^iZCdl
OnPreRender server conLrol evenL, 8
OnSelecLedlndexChanged aLLribuLe (server
conLrols), 22
OnUnload server conLrol evenL, 8
Open File command (File menu), 58
Open Web SiLe command (File menu), 87
Open Web SiLe dialog box, 87, 47
opening
Web pages, 58
Web siLes, 85-48
arbiLrary Web siLes, 87-48
exisLing Web siLes, 85
le sysLem Web siLes, 87-88
F1P-accessible Web siLes, 89-40
local llS Web siLes, 88-89
recenLly-used Web siLes, 86
remoLe Web siLes, 40-48
OperaLor value (Add WHFRF Clause dialog
box), 58
OpLions command (1ools menu), 69
OpLions dialog box, 86
ORDFR 8 seLLing (SelecL SLaLemenL dialog
box), 58
ouLlining, source code LexL ediLor, 69-70
C
page elemenLs, ormaLLing, CSS, 08
page layouL, cenLralizing wiLh masLer
pages, 95-96
page lie cycle, Web page delivery, 9
Page server conLrol, 6
Page_Load evenL handler, 99
parameLers, connecLion sLrings, 79, 8
Passive mode ield (Choose LocaLion dialog
box), 82
Password, Pwd parameLer, 8
Password parameLer (connecLion sLrings), 79
Place Code ln SeparaLe File check box, 82
Place Code ln SeparaLe File enLry (Add New lLem
page), 52, 86, 97
PorL ield (Choose LocaLion dialog box), 82
PosiLion command (LayouL menu), 64
ProducLAdd.aspx page, creaLing wiLh DeLailsview
conLrol, 69
ProducLld ield (ProducLs Lable), 45
producLion copy, Web siLes, 24
producLion Web siLe, requiremenLs, 5
ProducLName ield (ProducLs Lable), 45
ProducLPrice ield (ProducLs Lable), 45
ProducLs Lable (ConLosoMagic daLabase)
creaLing, 48-45
ields, 45
program code
compiling, 88
publishing, 82-88
sLoring, 82-88
programming model, ASP.NF1 2.0, 8
properLies
adding Lo sLyle sheeL rules (CSS), 2
8oundField, 6
DeLailsview conLrol, 70
DropDownLisL conLrol, 55-56
Menu conLrols, 82
ProperLies command (conLrol shorLcuL menus), 68
ProperLies dialog box, 42
ProperLies rame, 9
ProperLies window, seLLing conLrol
properLies, 58-6
providers, public web siLe, 5-6
Public uncLions, declaraLion, 92
Public variables, declaraLion, 92
public Web siLe, requiremenLs, 5
publishing
daLabases
connecLing Lo SOL Server, 75-79
copying SOL Server daLabases, 74-75
program code, 82-88
D
Ouery Developer, 46-48
Ouick Find command (Find and Replace
command), 78
Ouick Replace command (Find and Replace
command), 79
Ouick 1ag 1oolbar, 59
E
RecenL Files command (File menu), 58
RecenL ProjecLs command (File menu), 86
recenLly-used Web siLes, opening, 86
records,
adding, DeLailsview conLrol, 69-7
deleLing, 66
updaLing, 66
Reresh command (conLrol shorLcuL menus), 68
Reresh command (Copy Web dialog box, older
shorLcuL menus), 47
relaLive URLs
masLer pages, 06
user conLrols, 9-92
remoLe Web siLes, 29-8
opening, 40-48
speciying when copying Web siLes, 46-47
Remove SpliL command (Window menu), 7
Render meLhod, server conLrols, 5-6
RepeaLer conLrol, 56
Replace All command (Find and Replace
command), 79
Replace command (Find and Replace
command), 79
Replace ln Files command (Find and Replace
command), 79
replacing, LexL, source code LexL ediLor, 77-79
requiremenLs
producLion Web siLe, 5
LesLing, 4-5
Resize command (LayouL menu), 64
resources
ASP.NF1 2.0, 8
C#, 8
SOL Server Fxpress, 8
visual 8asic .NF1, 8
ResulLs pane, 48
ReLurn Only Unique Rows seLLing (SelecL
SLaLemenL dialog box), 52
rooL olders, Web siLes, 88
rowPlenLyDeLail server conLrol, 7
rowPlenLyHeading server conLrol, 7
Roxio, 7
Run as Server ConLrol command (conLrol shorLcuL
menus), 62
runaL="server" aLLribuLe (server conLrols), 5
X1146481Z01.indd 192 9/14/05 10:07:29 AM
>cYZm &.(
F
sample iles, insLallaLion, 8
Search and Replace dialog box, 78
securiLy. See also access
SelecL A MasLer Page dialog box, 0
SelecL All command (Copy Web dialog box,
older shorLcuL menus), 47
SelecL command (LayouL menu), 64
SelecL MasLer Page enLry (Add New lLem
page), 58
SelecL opLion, 66
SelecL SLaLemenL dialog box, 67-68
selecLors, sLyle rules (CSS), 09-0
server conLrols, 4-6
caLegorizaLion, 20
Web cusLom conLrols, 20, 20-2
Web user conLrols, 20, 85-98
ConLenL, 02
evenLs, 8-9
HLml1able, 7
HLml1ableRow, 7
LiLeral server conLrols, liL8anner1iLle, 98
Page, 6
Render meLhod, 5-6
rowPlenLyDeLail, 7
rowPlenLyHeading, 7
LblPlenLy, 7
Server ield (Choose LocaLion dialog box), 82
server insLances, 82
servers, Web siLes, 24
shared sLyle sheeLs (CSS), 09-4
adding properLies Lo sLyle sheeL rules, 2
adding Lhemes, 9-20
applying Lo Web pages, 8-4
creaLing new iles, 09
creaLing sLyle sheeL rules, 09-2
sharing SOL Server copies, 82
adminisLraLion, 82
Show SmarL 1ag command (conLrol shorLcuL
menus), 62
siLe map iles, creaLing, 26-80
siLeMap Lag, 27
SiLeMapDaLaSource daLa source conLrol, 0, 5
siLeMapNode Lag, 27
SiLeMapPaLh conLrol, 0, 84-86
siLe maps,
Skin File LemplaLe, Add New lLem dialog box, 7
skin iles, 6
skin Lags, 6
skins, adding Lo Lhemes, 6-9
smarL Lags, seLLing conLrol properLies, 68
snapping absoluLe posiLioning measuremenLs, 65
SoluLion Fxplorer, 9
adding conLrols Lo Web pages, 57-58
opening Web pages, 58
source code, LexL ediLor, 67-82
bookmarks, 72
deLecLion o synLax errors, 76-77
ediLing commands, 82
inding and replacing LexL, 77-79
ormaLLing source code, 80-8
Co 1o command (FdiL menu), 72
lnLelliSense, 78-76
ouLlining, 69-70
spliL view, 7
Lask lisL, 72-78
Source value (Add WHFRF Clause dialog
box), 58
Source view (Web pages), 54
source Web siLes, speciying when copying Web
siLes, 46-47
SpliL command (Window menu), 7
spliL view, source code LexL ediLor, 7
SOL pane, 47-48
SOL Server
accounLs, 85
connecLing Lo, 75-79
daLabases
aLLaching les, 84
conguring Add ConnecLion dialog box
or, 40-4
ConLosoMagic. See ConLosoMagic
daLabase
copying, 74-75
creaLing, 42-48, 48
insLance names, 40
visual SLudio versions, 40-4
neLwork libraries, 8
sharing copies, 82
visual Web Developer, 85-86
SOL Server Fxpress, 87, 85-86
resources, 8
SqlDaLaSource daLa source conLrol, 5
src= aLLribuLe (server conLrols), 5
SLandard conLrol group (1oolbox), 56
SLarL page, 6
sLaLemenL compleLion. See lnLelliSense
sLaLic menu iLems, 82
sLoring, program code, 82-88
sLrings
ASP.NF1 daLa ormaL sLrings, 6-62
connecLion, 77-79
ALLachDbFileName, 84
parameLers, 79, 8
parameLers, 8
SLyle 8uilder dialog box, 08
SLyle command (conLrol shorLcuL menus), 62
SLyle command (FormaL menu), 64, 08
sLyle sheeL rules (CSS), adding properLies Lo, 2
SLyles menu commands, Add SLyle Rule, 0
Synchronize SelecLed Files command (Copy Web
dialog box, older shorLcuL menus), 48
Synchronize SiLe command (Copy Web dialog
box, older shorLcuL menus), 48
synLax errors, deLecLion, source code LexL
ediLor, 76-77
SysLem.DaLa.SqlClienL, 76, 77
G
1able Designer, 44
Lables
adding Lo Web pages, 57
ConLosoMagic daLabase, ProducLs, 48-45
daLabases, modiying, 48-45
1able Designer, 44
updaLing conLenL, 46-48
viewing conLenL, 46-48
1abs node (OpLions dialog box, H1ML Lab), 8
1ag Speciic OpLions dialog box, 8
Lags, Web user conLrols, 90
@ RegisLer, 90
Web User ConLrol, 90
Lask lisL, source code LexL ediLor, 72-78
1ask LisL window, 72
LblPlenLy server conLrol, 7
LemplaLes (Add New lLem page), 52, 86, 97
1esL Ouery dialog box, 54-55
X1146481Z01.indd 193 9/14/05 10:07:30 AM
&.) B^Xgdhd[iK^hjVaLZW9ZkZadeZg'%%*:megZhh:Y^i^dc/7j^aYVLZWH^iZCdl
LesLing, requiremenLs, 4-5
LexL
inding, source code LexL ediLor, 77-79
replacing, source code LexL ediLor, 77-79
LexL ediLor, 67-82
bookmarks, 72
deLecLion o synLax errors, 76-77
ediLing commands, 82
inding and replacing LexL, 77-79
ormaLLing source code, 80-8
Co 1o command (FdiL menu), 72
lnLelliSense, 78-76
ouLlining, 69-70
spliL view, 7
Lask lisL, 72-78
1exL FdiLor Loolbar, 82
Lhemes, 5-28
adding CSS sLyle sheeLs, 9-20
adding skins, 6-9
applying Lo Web pages and siLes, 20-28
creaLing, 6
Loolbars
H1ML Source FdiLing, 77, 82
seLLing conLrol properLies, 64-65
1exL FdiLor, 82
1oolbox rame, 8
1oolbox window
adding conLrols Lo Web pages, 54-57
uncLional conLrol groups, 56
1ools menu commands, OpLions, 69
Lop-level daLabase drivers, 76-77
1ree view conLrol, 84
1ree view menus, linking Web siLe pages,
88-84
1ype SelecLor (CSS sLyle names), 45
H
updaLing
records, 66-68
Lables, 46-48
Use SOL Server AuLhenLicaLion opLion, 40
Use Windows AuLhenLicaLion opLion, 40
user conLrols, 20, 85-98
adding Lo Web pages, 88-89
applicaLions, 90-98
coding aLLribuLes, 92-98
CSS sLyles, 9
relaLive URLs, 9-92
Lags, 90
creaLing, 86-88
cusLomizing, vs. cusLom conLrols, 20
User ld parameLer, 8
User lD parameLer (connecLion sLrings), 79
User lnsLance parameLer, 8
user insLances, 74, 88-84
user inLerace, 8-
User Name and Password ield (Choose LocaLion
dialog box), 88
UserName conLrol, 0
I
validaLion conLrol group (1oolbox), 56
validaLion node (OpLions dialog box, H1ML
Lab), 8
value value (Add WHFRF Clause dialog box), 58
variables, Public declaraLion, 92
view menu commands
DocumenL OuLline, 60
1oolbars, H1ML Source FdiLing, 77
views, Lables, 46-48
virLual CD-ROM ConLrol Panel or Windows XP, 7
visual 8asic .NF1, resources, 8
visual SLudio, supporL or daLabases, 40-4
visual Web Developer 2005 Fxpress, 87
ASP.NF1 Lhemes, 5-28
ile sysLem Web siLes, 26
F1P-accessible Web siLes, 82-88
insLallaLion, 6
applicaLions, 8-4
local llS Web siLes, 28
vs. oLher producLs, 8-4
remoLe llS Web siLes, 80-8
source code, LexL ediLor, 67-82
visual Web Developer, SOL Server, 85-86
JK
Web cusLom conLrols, 20
H1ML server conLrols, 20
Web server conLrols, 20-22
Web pages
adding user conLrols, 88-89
applying Lhemes Lo, 20-28
creaLing, 5-58
delivery, 4-9
evenLs, 8-9
hierarchy o conLrols, 6-7
page lie cycle, 9
ediLing modes
Design view, 58
Source view, 54
Cridview, creaLing, 58-59
modiicaLions
adding conLrols, 54-58
adding Lables and layers rom Menu bar, 57
hyperlinks, 65-66
seLLing conLrol properLies, 58-65
opening, 58
seLLing conLrol properLies, 58-65
FormaL menu, 68-64
mouse, 6-68
ProperLies window, 58-6
smarL Lags, 68
Loolbars, 64-65
Web server conLrols, 20-22
Web siLe menu commands, Copy Web SiLe, 46
Web siLes
applying Lhemes Lo, 20-28
copying, 45-49
le selecLion, 47-49
speciying source and remoLe Web siLes,
46-47
creaLing, 28
le sysLem Web siLes, 25-26
F1P-accessible Web siLes, 25, 8-88
local llS Web siLes, 25, 27-29
remoLe llS Web siLes, 25, 29-8
cusLomizaLion,
hyperlinks, 25-86
breadcrumbs, 84-86
drop-down menus, 8-88
y-ouL menus, 8-88
siLe map les, 26-80
1ree view menus, 88-84
opening, 85-48
arbiLrary Web siLes, 87-48
X1146481Z01.indd 194 9/14/05 10:07:30 AM
>cYZm &.*
exisLing Web siLes, 85
le sysLem Web siLes, 87-88
F1P-accessible Web siLes, 89-40
local llS Web siLes, 88-89
recenLly-used Web siLes, 86
remoLe Web siLes, 40-48
producLion copy, 24
provider selecLion, 5-6
rooL older requiremenLs, 88
servers, 24
working copy, 24
Web User ConLrol Lag (Web user conLrols), 90
Web user conLrols, 20, 85-98
adding Lo Web pages, 88-89
applicaLions, 90-98
coding aLLribuLes, 92-98
CSS sLyles, 9
relaLive URLs, 9-92
Lags, 90
creaLing, 86-88
web.conig ile, copying, 48
WebParLs conLrol group (1oolbox), 56
WebsiLes, creaLing, local llS Web siLes, 25
WHFRF seLLing (SelecL SLaLemenL dialog box), 58
Window menu commands
Remove SpliL, 7
SpliL, 7
Windows AccounLs, 84-85
working copy, Web siLes, 24
XML (FxLensible Markup Language), 2
XmlDaLaSource daLa source conLrol, 5
X1146481Z01.indd 195 9/14/05 10:07:31 AM
X1146481Z01.indd 196 9/14/05 10:07:31 AM

You might also like