Visual Web Developer 2005 Express Edition
Visual Web Developer 2005 Express Edition
Visual Web Developer 2005 Express Edition
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
.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
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
.
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
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
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
. \|sJa|
C+
. o \|sJa| +
. \|sJa| C+
. o
\|sJa| +
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
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
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
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