Sei sulla pagina 1di 56

Introduction to Microsoft .

NET

Microsoft .NET is Microsoft's new Internet strategy. .NET was originally called NGWS.

NGWS - Next Generation Windows Services


Before the official announcement of .NET, the term NGWS was used for Microsoft's plans for producing an " nternet!"ased platform of Ne#t Generation Windows Ser$ices". Ste$e Ballmer %uote &anuar' ()))* "+eli$ering an nternet!"ased platform of Ne#t Generation Windows Ser$ices is the top priorit' of our compan'. The "rea,throughs we-re tal,ing a"out here include changes to the programming model, to the user interface, to the application integration model, the file s'stem, new .M/ schema....."

Microsoft. NET
The Microsoft. NET strateg' was presented "' Microsoft officials to the rest of the world in &une ()))*

.NET .NET .NET .NET .NET .NET .NET .NET

is Microsoft's new nternet and We" strateg' is N0T a new operating s'stem is a new nternet and We" "ased infrastructure deli$ers software as We" Ser$ices is a framewor, for uni$ersal ser$ices is a ser$er centric computing model will run in an' "rowser on an' platform is "ased on the newest We" standards

.NET Internet Standards


.NET is "uilt on the following nternet standards*

1TT2, the communication protocol "etween nternet 3pplications .M/, the format for e#changing data "etween nternet 3pplications S032, the standard format for re%uesting We" Ser$ices 4++ , the standard to search and disco$er We" Ser$ices

.NET Fra

ewor!

The .NET 5ramewor, is the infrastructure for the new Microsoft .NET 2latform. The .NET 5ramewor, is a common en$ironment for "uilding, deplo'ing, and

running We" Ser$ices and We" 3pplications. The .NET 5ramewor, contains common class li"raries ! li,e 3+0.NET, 3S2.NET and Windows 5orms ! to pro$ide ad$anced standard ser$ices that can "e integrated into a $ariet' of computer s'stems. The .NET 5ramewor, is language neutral. 6urrentl' it supports 677, 68, 9isual Basic, &Script :The Microsoft $ersion of &a$aScript; and 60B0/. Third! part' languages ! li,e Eiffel, 2erl, 2'thon, Smalltal,, and others ! will also "e a$aila"le for "uilding future .NET 5ramewor, applications. The new 9isual Studio.NET is a common de$elopment en$ironment for the new .NET 5ramewor,. t pro$ides a feature!rich application e#ecution en$ironment, simplified de$elopment and eas' integration "etween a num"er of different de$elopment languages.

"dditional Infor

ation

The .NET plan includes a new $ersion of the Windows operating s'stem, a new $ersion of 0ffice, and a $ariet' of new de$elopment software for programmers to "uild We"!"ased applications. The "ac,ground for .NET is part of Microsoft's new strateg' to ,eep Windows the dominant operating s'stem in the mar,et, as computing "egins to mo$e awa' from des,top computers toward nternet ena"led de$ices, such as hand!held computers and cell phones. The most $isual components of the new .NET framewor, are the new nternet nformation Ser$er <.), with 3S2.NET and 3+0.NET support, 9isual Studio.NET software tools to "uild We"!"ased software, and new .M/ support in the S=/ Ser$er ())) data"ase. Bill Gates is super$ising the .NET pro>ect.

NET #uilding #loc!s

.NET #uilding #loc!s is a set of core Internet Services.

We$ Services
We" Ser$ices pro$ide data and ser$ices to other applications. 5uture applications will access We" Ser$ices $ia standard We" 5ormats :1TT2, 1TM/, .M/, and S032;, with no need to ,now how the We" Ser$ice itself is implemented. We" Ser$ices are main "uilding "loc,s in the Microsoft .NET programming model.

Standard %o

unication

0fficial We" standards :.M/, 4++ , S032; will "e used to descri"e what nternet data is, and to descri"e what We" Ser$ices can do. 5uture We" applications will "e "uilt on fle#i"le ser$ices that can interact and e#change data, without the loss of integrit'.

Internet Storages
.NET offers secure and addressa"le places to store data and applications on the We". 3llowing all t'pes of nternet de$ices :26s, 2almtops, 2hones; to access data and applications. These We" Ser$ices are "uilt on Microsoft's e#isting NT5S, S=/ Ser$er, and E#change technologies.

Internet &yna

ic &elivery

?elia"le automatic upgrades "' demand and installation independent applications. .NET will support rapid de$elopment of applications that can "e d'namicall' reconfigured.

Internet Identity
.NET supports man' different le$els of authentication ser$ices li,e passwords, wallets, and smart cards. These ser$ices are "uilt on e#isting Microsoft 2assport and Windows 3uthentication technologies.

Internet Messaging
.NET supports integration of messaging, e!mail, $oice!mail, and fa# into one unified nternet Ser$ice, targeted for all ,inds of 26s or smart nternet de$ices. These ser$ices are "uilt on e#isting 1otmail, E#change and nstant Messenger technologies.

Internet %alendar
.NET supports nternet integration of wor,, social, and pri$ate home calendars. 3llowing all t'pes of nternet de$ices :26s, 2almtops, 2hones; to access the data. These ser$ices are "uilt on e#isting 0utloo, and 1otmail technologies.

Internet &irectory Services


.NET supports a new ,ind of director' ser$ices that can answer .M/ "ased %uestions a"out nternet Ser$ices, far more e#actl' than search engines and 'ellow pages. These ser$ices are "uilt on the 4++ standard.

NET Software

.NET is a

ix of tec'nologies( standards and develo)

ent tools

Windows .NET
Toda', Windows ())) and Windows .2 form the "ac,"one of .NET. n the future, the .NET infrastructure will "e integrated into all Microsoft's operating s'stems, des,top and ser$er products. Windows .NET is the ne#t generation Windows. t will pro$ide support for all the .NET "uilding "loc,s and .NET digital media. Windows .NET will "e self!supporting with updates $ia nternet as users need them.

*ffice .NET
3 new $ersion of Microsoft 0ffice ! 0ffice .NET ! will ha$e a new .NET architecture "ased on nternet clients and We" Ser$ices. With 0ffice .NET, "rowsing, communication, document handling and authoring will "e integrated within a .M/!"ased en$ironment which allow users to store their documents on the nternet.

"ctive Server +ages - "S+ .NET


3S2 .NET is the latest $ersion of 3S2. t includes We" Ser$ices to lin, applications, ser$ices and de$ices using 1TT2, 1TM/, .M/ and S032. New in 3S2 .NET*

New /anguage Support 2rogramma"le 6ontrols E$ent +ri$en 2rogramming .M/ Based 6omponents 4ser 3uthentication 4ser 3ccounts and ?oles 1igh Scala"ilit' 6ompiled 6ode Eas' 6onfiguration Eas' +eplo'ment Not 3S2 6ompati"le ncludes 3+0 .NET

@ou can read more a"out 3S2 .NET and 3+0 .NET in our 3S2 .NET Tutorial.

,isual Studio .NET

The latest $ersion of 9isual Studio ! 9isual Studio .NET ! incorporates 3S2 .NET, 3+0 .NET, We" Ser$ices, We" 5orms, and language inno$ations for 9isual Basic. The de$elopment tools ha$e deep .M/ support, an .M/!"ased programming model and new o">ect!oriented programming capa"ilities.

,isual #asic .NET


9isual Basic .NET has added language enhancements, ma,ing it a full o">ect!oriented programming language.

S-. Server /000


S=/ Ser$er ())) is a full' we"!ena"led data"ase. S=/ Ser$er ())) has strong support for .M/ and 1TT2 which are two of the main infrastructure technologies for .NET. Some of the most important new S=/ Ser$er features are direct access to the data"ase from a "rowser, %uer' of relational data with results returned as .M/, as well as storage of .M/ in relational formats.

Internet Infor

ation Services 1.0

S <.) has strong support for more programming to ta,e place on the ser$er, to allow the new We" 3pplications to run in an' "rowser on an' platform

.NET We$ Services

We$ services are s

all units of code $uilt to 'andle a li

ited tas!.

W'at are We$ Services2 S


We" We" We" We" We" We" ser$ices ser$ices ser$ices ser$ices ser$ices ser$ices are small units of code are designed to handle a limited set of tas,s use .M/ "ased communicating protocols are independent of operating s'stems are independent of programming languages connect people, s'stems and de$ices

all 3nits of %ode

We" ser$ices are small units of code designed to handle a limited set of tas,s. 3n e#ample of a we" ser$ice can "e a small program designed to suppl' other applications with the latest stoc, e#change prices. 3nother e#ample can "e a small program designed to handle credit card pa'ment.

4M. #ased We$ +rotocols

We" ser$ices use the standard we" protocols 1TT2, .M/, S032, WS+/, and 4++ .

HTTP
1TT2 :1'perte#t Transfer 2rotocol; is the World Wide We" standard for communication o$er the nternet. 1TT2 is standardiAed "' the World Wide We" 6onsortium :WB6;.

XML
.M/ :e.tensi"le Mar,up /anguage; is a well ,nown standard for storing, carr'ing, and e#changing data. .M/ is standardiAed "' the WB6. @ou can read more a"out .M/ in our .M/ tutorial.

SOAP
S032 :Simple 0">ect 3ccess 2rotocol; is a lightweight platform and language neutral communication protocol that allows programs to communicate $ia standard nternet 1TT2. S032 is standardiAed "' the WB6. @ou can read more a"out S032 in our S032 tutorial.

WSDL
WS+/ :We" Ser$ices +escription /anguage; is an .M/!"ased language used to define we" ser$ices and to descri"e how to access them. WS+/ is a suggestion "' 3ri"a, BM and Microsoft for descri"ing ser$ices for the WB6 .M/ 3cti$it' on .M/ 2rotocols. @ou can read more a"out WS+/ in our WS+/ tutorial.

UDDI
4++ :4ni$ersal +escription, +isco$er' and ntegration; is a director' ser$ice where "usinesses can register and search for we" ser$ices. 4++ is a pu"lic registr', where one can pu"lish and in%uire a"out we" ser$ices.

Inde)endent of *)erating Syste

Since we" ser$ices use .M/ "ased protocols to communicate with other s'stems, we" ser$ices are independent of "oth operating s'stems and programming languages. 3n application calling a we" ser$ice will alwa's send its re%uests using .M/, and get its answer returned as .M/. The calling application will ne$er "e concerned a"out the operating s'stem or the programming language running on the other computer.

#enefits of We$ Services


Easier to communicate "etween applications Easier to reuse e#isting ser$ices Easier to distri"ute information to more consumers ?apid de$elopment

We" ser$ices ma,e it easier to communicate "etween different applications. The' also ma,e it possi"le for de$elopers to reuse e#isting we" ser$ices instead of writing new ones. We" ser$ices can create new possi"ilities for man' "usinesses "ecause it pro$ides an eas' wa' to distri"ute information to a large num"er of consumers. 0ne e#ample could "e flight schedules and tic,et reser$ation s'stems.

%lient and Server Standards

T'e )aragra)'s $elow descri$es W5Sc'ools' vision a$out future Internet &istri$uted "))lications.

Executa$les( %66 7and 8ava too9

ust die

Neither 677 nor &a$a can e$er create standard components that can run on all computers. There is no room for these languages in future distri"uted applications. E#ecuta"les are not standard. 60M o">ects are not standard, +//!files are not standard. ?egistr' settings are not standard. N !files are not standard. None of these components must "e allowed to destro' 'our dream of a standard distri"uted application that will run on almost an' computer in the world.

%lients

ust $e Standard Internet #rowsers

3pplication clients must "e standard clients without an' additional components. No part of the applications must "e stored on client computers. The application must ne$er use, or rel' on, an' components, dll! or ini!files, registr' settings or an' other non standard settings or files stored on the client computer. :Then 'ou can start calling it a Thin 6lient;. 0ur "est suggestion is to let all clients use standard nternet "rowsers li,e nternet E#plorer or Netscape Na$igator running on Windows or Mac computers.

Servers

ust $e Standard Internet Servers

3pplication ser$ers must "e standard nternet ser$ers running standard software without an' additional components. The application must ne$er use, or rel' on, an' components, dll! or ini!files, registr' settings or an' other non standard settings or files stored on the ser$er. 0ur "est suggestion is to use a standard nternet ser$er li,e nternet nformation Ser$ices : S;, with a standard re%uest!handler li,e 3cti$e Ser$er 2ages :3S2;, and a standard data"ase connector li,e 3cti$e +ata 0">ects :3+0;. 3s 'our data!store 'ou should use a standard S=/ "ased data"ase li,e 0racle or Microsoft's S=/ Ser$er.

"))lications

ust use Internet %o

unication

3pplication clients and ser$ers must not "e allowed to communicate $ia an' proprietar' protocol. 6lients must re%uest ser$ers $ia a standard nternet protocol and ser$ers must respond $ia the same protocol. 6lients must "e a"le to use an' ser$ice without ha$ing to maintain a permanent connection to the ser$er. 0ur "est suggestion is to let ser$ers "e re%uested with standard stateless nternet 1TT2 re%uests. Ser$ers should respond with a standard stateless nternet 1TT2 response.

"))lications

ust $e Services

T'e )aragra)'s $elow descri$es W5Sc'ools' vision a$out future Internet &istri$uted "))lications.

"))lications

ust $e a Set of Services

3pplications can no longer "e allowed to contain large masses of compiled e#ecuta"le code. 3pplications must "e "ro,en down into a num"er of smaller indi$idual ser$ices that are easier to create and easier to maintain. ndi$idual ser$ices should "e de$eloped and maintained "' smaller groups of people. Ser$ices are not the same as e#ecuta"les, or components, or +//'s. Ser$ices should "e answers to su"mitted re%uests. Ser$ices should "e returned as data. 0ur "est suggestion is to de$elop ser$ices as a num"er of ser$er!side 1TM/ andCor .M/ pages.

Services

ust not $e +ur)ose #uilt

0ur histor' is full of applications that were purpose "uilt for a single tas,. Man' of these applications died "efore the' were introduced, "ecause the' could not manage new changes in the re%uirements. This is a terri"le waste of mone' and time. We :and the people that pa' for our applications; want to create fle#i"le applications that are so generaliAed that the' can gracefull' support future changes. 5uture ! not e$en thought a"out ! changes should easil' hoo, into our application without crum"ling or destro'ing it. 0ur "est suggestion is to create fle#i"le standard ser$ices that can "e used to ser$e a lot of different re%uests.

Services

ust $e easy to %reate and Edit

Ser$ices should not "e coded if it can "e a$oided. f a ser$ice has to "e coded, our "est suggestion is to use scripts. Ser$ices should ne$er "e compiled into e#ecuta"les. That ma,es ser$ices too hard to access and to edit. 3n' pre!compiled component used in an application will threaten the possi"ilit' of creating an application that can mo$e, scale and gracefull' support future e#tensions or changes. Ser$ices should "e created and modified "' editing their properties and methods, not "' changing their e#ecuta"le code. 0ur "est suggestion is to use an .M/ editor to create and edit ser$ices, and to use a standard ser$ice engine to pro$ide ser$ices "' e#ecuting the ser$ice description. The ser$ice descriptions should "e stored in a data store li,e a data"ase or in an .M/C1TM/ file.

Services and data

ust $e Self &escri$ing

3pplication clients must "e a"le to %uer' a ser$er for a ser$ice and to as, for the current ser$er functions. 6lients and ser$ers must also "e a"le to e#change data in a wa' so that "oth understand each element in the data. 0ur "est suggestion is to use an .M/ "ased information $oca"ular' with a +T+ :+ocument T'pe +efinition; to e#change ser$er functions, and to use .M/ to e#change data.

Future +roof "))lications

T'e )aragra)'s $elow descri$es W5Sc'ools' vision a$out future Internet &istri$uted "))lications.

"))lications

ust Su))ort Future %'anges

3pplications must "e aware of future changes and gracefull' ad>ust to changes in either the amount of ser$ices or in the e#change format. The application and the data e#change format must support

"oth e#tensions, remo$ed elements and $ersion controls. 0ur "est suggestion is to use .M/ with an .M/ Schema.

"))lications

ust Scale and :elocate

3pplications must "e a"le to scale from supporting a few to man' thousand re%uests per da'. Ser$er ser$ices must "e a"le to spread from one ser$er to man', or to mo$e from one ser$er to another without "rea,ing the application. 0ur "est suggestion is to ma,e ser$er ser$ices independent of ph'sical ser$er, and to use standard nternet 4niform ?esource /ocators :4?/; or a director' ser$ice to locate the ser$ices.

"))lications

ust Su))ort ot'er "))lications

3pplications should "e a"le to cooperate with other applications. 0ur "est suggestion is create all applications with the same rules, and to lin, applications together with standard nternet lin,s.

"))lications

ust Su))ort Future Internet Standards

3pplications should "e made read' to support the new nternet Standards as the' emerge from WB6.

Tutorial

"S+ .NET Tutorial


"S+ .NET Tutorial
In t'is tutorial you will learn a$out "S+ .NET "S+ .NET is a )art of t'e Microsoft .NET fra ewor!( and a very )owerful tool for a!ing dyna ic and interactive we$ )ages. Start learning 3S2 .NETD

"S+ .NET :eferences


3t WBSchools 'ou will find complete 3S2 .NET references a"out "uilt!in o">ects and components, and their properties and methods*

1TM/ ser$er controls reference We" ser$er controls reference 9alidation ser$er controls reference

"S+ .NET Exa

)les

3S2 .NET e#amples 3 collection of 3S2. NET e#amples.

Ta$le of %ontents
3S2 .NET ntroduction This chapter e#plains what 3S2 .NET is. 3S2 .NET $s 3S2 This chapter e#plains the differences "etween 3S2 .NET and 3S2. 3S2 .NET nstalling This chapter e#plains how to install 3S2 .NET. 3S2 .NET 2ages This chapter e#plains how to create 'our first simple 3S2 .NET page. 3S2 .NET Ser$er controls This chapter e#plains the 3S2 .NET ser$er controls. 3S2 .NET E$ents This chapter e#plains some of the 3S2 .NET e$ent handlers.

ASP .NET Forms


3S2 .NET We" forms This chapter e#plains 3S2 .NET We" forms. 3S2 .NET Maintaining the 9iewState This chapter e#plains how to maintain the 9iewState. 3S2 .NET The Te#tBo# control This chapter e#plains the "asics of the asp*Te#tBo# control. 3S2 .NET The Button control This chapter e#plains the "asics of the asp*Button control.

ASP .NET Binding


3S2 .NET +ata "inding This chapter e#plains 3S2 .NET data "inding. 3S2 .NET The 3rra'/ist o">ect This chapter e#plains the 3S2 .NET 3rra'/ist o">ect. 3S2 .NET The 1ashta"le o">ect This chapter e#plains the 3S2 .NET 1ashta"le o">ect. 3S2 .NET The Sorted/ist o">ect This chapter e#plains the 3S2 .NET Sorted/ist o">ect. 3S2 .NET .M/ files This chapter e#plains data "inding to an .M/ file.

3S2 .NET The asp*?epeater control This chapter e#plains data "inding to an .M/ file with the ?epeater control. 3S2 .NET The asp*+ata/ist control This chapter e#plains data "inding to an .M/ file with the +ata/ist control.

ASP .NET Database


3S2 .NET +B 6onnection This chapter introduces 3+0 .NET and connecting to a data"ase.

ASP .NET e!eren"es


3S2 .NET 1TM/ Ser$er 6ontrols ?eference 3 complete 1TM/ Ser$er 6ontrols reference with properties, methods, and e$ents. 3S2 .NET We" Ser$er 6ontrols ?eference 3 complete We" Ser$er 6ontrols reference with properties, methods, and e$ents. 3S2 .NET 9alidation Ser$er 6ontrols ?eference 3 complete 9alidation Ser$er 6ontrols reference with properties, methods, and e$ents.

ASP .NET E#am$%es


3S2 .NET E#amples 3 collection of 3S2 .NET e#amples.

&ifferences $etween "S+ and "S+ .NET

"S+ .NET 'as $etter language su))ort( a large set of new controls and 4M. $ased co )onents( and $etter user aut'entication. "S+ .NET )rovides increased )erfor ance $y running co )ati$le wit' "S+. )iled code.

"S+ .NET code is not fully $ac!ward co

New in "S+ .NET


Better language support 2rogramma"le controls E$ent!dri$en programming .M/!"ased components 4ser authentication, with accounts and roles 1igher scala"ilit' ncreased performance ! 6ompiled code Easier configuration and deplo'ment Not full' 3S2 compati"le

.anguage Su))ort
3S2 .NET uses the new 3+0 .NET. 3S2 .NET supports full 9isual Basic, not 9BScript. 3S2 .NET supports 68 :6 sharp; and 677. 3S2 .NET supports &Script as "efore.

"S+ .NET %ontrols


3S2 .NET contains a large set of 1TM/ controls. 3lmost all 1TM/ elements on a page can "e defined as 3S2 .NET control o">ects that can "e controlled "' scripts. 3S2 .NET also contains a new set of o">ect oriented input controls, li,e programma"le list "o#es and $alidation controls. 3 new data grid control supports sorting, data paging, and e$er'thing 'ou e#pect from a dataset control.

Event "ware %ontrols


3ll 3S2 .NET o">ects on a We" page can e#pose e$ents that can "e processed "' 3S2 .NET code. /oad, 6lic, and 6hange e$ents handled "' code ma,es coding much simpler and much "etter organiAed.

"S+ .NET %o

)onents

3S2 .NET components are hea$il' "ased on .M/. /i,e the new 3+ ?otator, that uses .M/ to store ad$ertisement information and configuration.

3ser "ut'entication
3S2 .NET supports forms!"ased user authentication, including coo,ie management and automatic redirecting of unauthoriAed logins. :@ou can still do 'our custom login page and custom user chec,ing;.

3ser "ccounts and :oles


3S2 .NET allows for user accounts and roles, to gi$e each user :with a gi$en role; access to different ser$er code and e#ecuta"les.

;ig' Scala$ility
Much has "een done with 3S2 .NET to pro$ide greater scala"ilit'.

Ser$er to ser$er communication has "een greatl' enhanced, ma,ing it possi"le to scale an application o$er se$eral ser$ers. 0ne e#ample of this is the a"ilit' to run .M/ parsers, .S/ transformations and e$en resource hungr' session o">ects on other ser$ers.

%o

)iled %ode

The first re%uest for an 3S2 .NET page on the ser$er will compile the 3S2 .NET code and ,eep a cached cop' in memor'. The result of this is greatl' increased performance.

Easy %onfiguration
6onfiguration of 3S2 .NET is done with plain te#t files. 6onfiguration files can "e uploaded or changed while the application is running. No need to restart the ser$er. No more meta"ase or registr' puAAle.

Easy &e)loy

ent

No more ser$er restart to deplo' or replace compiled code. 3S2 .NET simpl' redirects all new re%uests to the new code.

%o

)ati$ility

3S2 .NET is not full' compati"le with earlier $ersions of 3S2, so most of the old 3S2 code will need some changes to run under 3S2 .NET. To o$ercome this pro"lem, 3S2 .NET uses a new file e#tension ".asp#". This will ma,e 3S2 .NET applications a"le to run side "' side with standard 3S2 applications on the same ser$er.

Installing "S+ .NET

"S+ .NET is easy to install. 8ust follow t'e instructions $elow.

W'at <ou Need


A Windo&s 'om$(ter
3S2 .NET is a Microsoft technolog'. To run 3S2 .NET 'ou need a computer capa"le of running Windows.

Windo&s )*** or XP
f 'ou are serious a"out de$eloping 3S2 .NET applications 'ou should install Windows ())) 2rofessional or Windows .2 2rofessional. n "oth cases, ma,e sure 'ou install the nternet nformation Ser$ices : S; from the 3ddC?emo$e Windows components dialog.

Ser+i"e Pa",s and U$dates


Before 3S2 .NET can "e installed on 'our computer, it is necessar' to ha$e all rele$ant ser$ice pac,s and securit' updates installed. The easiest wa' to do this is to acti$ate 'our Windows nternet 4pdate. When 'ou access the Windows 4pdate page, 'ou will "e instructed to install the latest ser$ice pac,s and all critical securit' updates. 5or Windows ())), ma,e sure 'ou install Ser$ice 2ac, (. will also recommend that 'ou install nternet E#plorer <. ?ead the note a"out connection speed and download time at the "ottom of this page.

:e

ove <our #eta ,ersion

f 'ou ha$e a Beta $ersion of 3S2 .NET installed, we recommend that 'ou completel' uninstall it. 0r e$en "etter* start with a fresh Windows ())) or .2 installation.

Install .NET
5rom 'our Windows 4pdate 'ou can now select to install the Microsoft .NET 5ramewor,. 3fter download, the .NET framewor, will install itself on 'our computer. There are not an' options to select for the installation. <ou s'ould now $e ready to develo) your first "S+ .NET a))lication.

T'e .NET Software &evelo)

ent =it

f 'ou ha$e the necessar' "andwidth to download o$er EB) MB, 'ou might consider downloading the full Microsoft .NET Software +e$elopment Fit :S+F;. We full' recommend getting the S+F for learning more a"out .NET and for the documentation, samples, and tools included.

%onnection S)eed and &ownload Ti

f 'ou ha$e a slow nternet connection, 'ou might ha$e pro"lems downloading large files li,e the ser$ice pac,s, the S+F and the latest $ersion of nternet E#plorer. f download speed is a pro"lem, our "est suggestion is to get the latest files from someone else, from a colleague, from a friend, or from one of the 6+s that comes with man' popular computer magaAines. /oo, for Windows ())) Ser$ice 2ac, (, nternet E#plorer <, and the Microsoft .NET 5ramewor,.

"S+ .NET - We$ +ages

" si

)le "S+ .NET )age loo!s >ust li!e an ordinary ;TM. )age.

;ello W5Sc'ools
To start learning 3S2 .NET, we will construct a $er' simple 1TM/ page that will displa' "1ello WBSchools" in an nternet "rowser li,e this*

;ello W5Sc'ools?

;ello W5Sc'ools in ;TM.


This code displa's the e#ample as an 1TM/ page*

<html> <body bgcolor="yellow"> <center> <h2>Hello W3Schools!</h2> </center> </body> </html>


f 'ou want to tr' it 'ourself, sa$e the code in a file called " first)age.'t file li,e this* firstpage.htm ", and create a lin, to the

;ello W5Sc'ools in "S+ .NET


The simplest wa' to con$ert an 1TM/ page into an 3S2 .NET page is to cop' the 1TM/ file to a new file with an .as)x e#tension. This code displa's our e#ample as an 3S2 .NET page*

<html> <body bgcolor="yellow"> <center> <h2>Hello W3Schools!</h2> </center> </body> </html>


f 'ou want to tr' it 'ourself, sa$e the code in a file called " first)age.as)x", and create a lin, to the file li,e this* firstpage.asp#

;ow &oes it Wor!2


5undamentall' an 3S2 .NET page is >ust the same as an 1TM/ page. 3n 1TM/ page has the e#tension .htm. f a "rowser re%uests an 1TM/ page from the ser$er, the ser$er sends the page to the "rowser without an' modifications.

3n 3S2 .NET page has the e#tension .asp#. f a "rowser re%uests an 3S2 .NET page, the ser$er processes an' e#ecuta"le code in the page, "efore the result is sent "ac, to the "rowser. The 3S2 .NET page a"o$e does not contain an' e#ecuta"le code, so nothing is e#ecuted. n the ne#t e#amples we will add some e#ecuta"le code to the page to demonstrate the difference "etween static 1TM/ pages and d'namic 3S2 pages.

%lassic "S+
3cti$e Ser$er 2ages :3S2; has "een around for se$eral 'ears. With 3S2, e#ecuta"le code can "e placed inside 1TM/ pages. 2re$ious $ersions of 3S2 :"efore 3S2 .NET; are often called 6lassic 3S2. 3S2 .NET is not full' compati"le with 6lassic 3S2, "ut most 6lassic 3S2 pages will wor, fine as 3S2 .NET pages, with onl' minor changes. f 'ou want to learn more a"out 6lassic 3S2, please $isit our 3S2 Tutorial.

&yna

ic +age in %lassic "S+

To demonstrate how 3S2 can displa' pages with d'namic content, we ha$e added some e#ecuta"le code :in red; to the pre$ious e#ample*

<html> <body bgcolor="yellow"> <center> <h2>Hello W3Schools!</h2> <p><%Response.Wr te!now!""%></p> </center> </body> </html>
The code inside the GH !!HI tags is e#ecuted on the ser$er. ?eponse.Write is 3S2 code for writing something to the 1TM/ output stream. Now:; is a function returning the ser$ers current date and time. f 'ou want to tr' it 'ourself, sa$e the code in a file called " dyn)age.as)", and create a lin, to the file li,e this* d'npage.asp

&yna

ic +age in "S+ .NET

This following code displa's our e#ample as an 3S2 .NET page*

<html> <body bgcolor="yellow"> <center> <h2>Hello W3Schools!</h2> <p><%Response.Wr te!now!""%></p>

</center> </body> </html>


f 'ou want to tr' it 'ourself, sa$e the code in a file called " dyn)age.as)x", and create a lin, to the file li,e this* d'npage.asp#

"S+ .NET vs %lassic "S+


The pre$ious e#amples didn't demonstrate an' differences "etween 3S2 .NET and 6lassic 3S2. 3s 'ou can see from the two latest e#amples there are no differences "etween the two 3S2 and 3S2 .NET pages. n the ne#t chapters 'ou will see how ser$er controls ma,e 3S2. NET more powerful than 6lassic 3S2.

"S+ .NET - Server %ontrols

Server controls are tags t'at are understood $y t'e server.

.i

itations in %lassic "S+

The listing "elow was copied from the pre$ious chapter*

<html> <body bgcolor="yellow"> <center> <h2>Hello W3Schools!</h2> <p><%Response.Wr te!now!""%></p> </center> </body> </html>
The code a"o$e illustrates a limitation in 6lassic 3S2* The code "loc, has to "e placed where 'ou want the output to appear. With 6lassic 3S2 it is impossi"le to separate e#ecuta"le code from the 1TM/ itself. This ma,es the page difficult to read, and difficult to maintain.

"S+ .NET - Server %ontrols


3S2 .NET has sol$ed the "spaghetti!code" pro"lem descri"ed a"o$e with ser$er controls. Ser$er controls are tags that are understood "' the ser$er. There are three ,inds of ser$er controls*

1TM/ Ser$er 6ontrols ! Traditional 1TM/ tags We" Ser$er 6ontrols ! New 3S2 .NET tags 9alidation Ser$er 6ontrols ! 5or input $alidation

"S+ .NET - ;TM. Server %ontrols


1TM/ ser$er controls are 1TM/ tags understood "' the ser$er. 1TM/ elements in 3S2 .NET files are, "' default, treated as te#t. To ma,e these elements programma"le, add a runatJ"ser$er" attri"ute to the 1TM/ element. This attri"ute indicates that the element should "e treated as a ser$er control. The id attri"ute is added to identif' the ser$er control. The id reference can "e used to manipulate the ser$er control at run time. Note@ 3ll 1TM/ ser$er controls must "e within a GformI tag with the runatJ"ser$er" attri"ute. The runatJ"ser$er" attri"ute indicates that the form should "e processed on the ser$er. t also indicates that the enclosed controls can "e accessed "' ser$er scripts. n the following e#ample we declare an 1tml3nchor ser$er control in an .asp# file. Then we manipulate the 1?ef attri"ute of the 1tml3nchor control in an e$ent handler :an e$ent handler is a su"routine that e#ecutes code for a gi$en e$ent;. The 2ageK/oad e$ent is one of man' e$ents that 3S2 .NET understands*

<scr pt r#n$t="ser%er"> S#b &$ge'(o$d l n)*.HRe+="http,//www.w3schools.com" -nd S#b </scr pt> <html> <body> <+orm r#n$t="ser%er"> <$ d="l n)*" r#n$t="ser%er">. s t W3Schools!</$> </+orm> </body> </html>
The e#ecuta"le code itself has "een mo$ed outside the 1TM/.

"S+ .NET - We$ Server %ontrols


We" ser$er controls are special 3S2 .NET tags understood "' the ser$er. /i,e 1TM/ ser$er controls, We" ser$er controls are also created on the ser$er and the' re%uire a runatJ"ser$er" attri"ute to wor,. 1owe$er, We" ser$er controls do not necessaril' map to an' e#isting 1TM/ elements and the' ma' represent more comple# elements. The s'nta# for creating a We" ser$er control is*

<$sp,control'n$me

d="some' d" r#n$t="ser%er" />

n the following e#ample we declare a Button ser$er control in an .asp# file. Then we create an e$ent handler for the 6lic, e$ent which changes the te#t on the "utton*

<scr pt r#n$t="ser%er"> S#b s#bm t!So#rce /s 0b1ect2 e /s -%ent/rgs" b#tton*.3e4t="5o# cl c)ed me!" -nd S#b </scr pt> <html> <body> <+orm r#n$t="ser%er"> <$sp,6#tton d="b#tton*" 3e4t="7l c) me!" r#n$t="ser%er" 0n7l c)="s#bm t"/> </+orm> </body> </html>

"S+ .NET - ,alidation Server %ontrols


9alidation ser$er controls is used to $alidate user!input. f the user!input does not pass $alidation, it will displa' an error message to the user. Each $alidation control performs a specific t'pe of $alidation :li,e $alidating against a specific $alue or a range of $alues;. B' default, page $alidation is performed when a Button, mageButton, or /in,Button control is clic,ed. @ou can pre$ent $alidation when a "utton control is clic,ed "' setting the 6auses9alidation propert' to false. The s'nta# for creating a 9alidation ser$er control is*

<$sp,control'n$me

d="some' d" r#n$t="ser%er" />

n the following e#ample we declare one Te#tBo# control, one Button control, and one ?ange9alidator control in an .asp# file. f $alidation fails, the te#t "The $alue must "e from E to E))D" will "e displa'ed in the ?ange9alidator control*

<html> <body> <+orm r#n$t="ser%er"> -nter $ n#mber +rom * to *88, <$sp,3e4t6o4 d="tbo4*" r#n$t="ser%er" /> <br /><br /> <$sp,6#tton 3e4t="S#bm t" r#n$t="ser%er" /> <br /> <$sp,R$nge.$l d$tor 7ontrol3o.$l d$te="tbo4*" 9 n m#m.$l#e="*" 9$4 m#m.$l#e="*88" 3ype=":nteger" -n$ble7l entScr pt="+$lse" 3e4t="3he %$l#e m#st be +rom * to *88!" r#n$t="ser%er" /> </+orm> </body> </html>

"S+ .NET - Events

"n Event ;andler is a su$routine t'at executes code for a given event.

"S+ .NET - Event ;andlers


/oo, at the following code*

<% lbl*.3e4t="3he d$te $nd t me s " ; now!" %> <html> <body> <+orm r#n$t="ser%er"> <h3><$sp,l$bel d="lbl*" r#n$t="ser%er" /></h3> </+orm> </body> </html>
When will the code a"o$e "e e#ecutedL The answer is* "@ou don't ,now..."

T'e +ageA.oad Event


The 2ageK/oad e$ent is one of man' e$ents that 3S2 .NET understands. The 2ageK/oad e$ent is triggered when a page loads, and 3S2 .NET will automaticall' call the su"routine 2ageK/oad, and e#ecute the code inside it*

<scr pt r#n$t="ser%er"> S#b &$ge'(o$d lbl*.3e4t="3he d$te $nd t me s " ; now!" -nd S#b </scr pt> <html> <body> <+orm r#n$t="ser%er"> <h3><$sp,l$bel d="lbl*" r#n$t="ser%er" /></h3> </+orm> </body> </html>
Note@ The 2ageK/oad e$ent contains no o">ect references or e$ent argumentsD E#ample

T'e +age.Is+ost#ac! +ro)erty


The 2ageK/oad su"routine runs E9E?@ time the page is loaded. f 'ou want to e#ecute the code in the 2ageK/oad su"routine onl' the 5 ?ST time the page is loaded, 'ou can use the 2age. s2ostBac, propert'. f the 2age. s2ostBac, propert' is false, the page is loaded for the first time, if it is true, the page is posted "ac, to the ser$er :i.e. from a "utton clic, on a form;*

<scr pt r#n$t="ser%er"> S#b &$ge'(o$d + <ot &$ge.:s&ost6$c) then lbl*.3e4t="3he d$te $nd t me s " ; now!" end + -nd S#b S#b s#bm t!s /s 0b1ect2 e /s -%ent/rgs" lbl2.3e4t="Hello World!" -nd S#b </scr pt> <html> <body> <+orm r#n$t="ser%er"> <h3><$sp,l$bel d="lbl*" r#n$t="ser%er" /></h3> <h3><$sp,l$bel d="lbl2" r#n$t="ser%er" /></h3> <$sp,b#tton te4t="S#bm t" oncl c)="s#bm t" r#n$t="ser%er" /> </+orm> </body> </html>
The e#ample a"o$e will write the "The date and time is...." message onl' the first time the page is loaded. When a user clic,s on the Su"mit "utton, the su"mit su"routine will write "1ello WorldD" to the second la"el, "ut the date and time in the first la"el will not change. E#ample

Gscript runatJ"ser$er"I Su" 2ageK/oad if Not 2age. s2ostBac, then l"lE.Te#tJ"The date and time is " M now:; end if End Su" Su" su"mit:s 3s 0">ect, e 3s E$ent3rgs; l"l(.Te#tJ"1ello WorldD" End Su" GCscriptI GhtmlI G"od'I Gform runatJ"ser$er"I GhBIGasp*la"el idJ"l"lE" runatJ"ser$er" CIGChBI GhBIGasp*la"el idJ"l"l(" runatJ"ser$er" CIGChBI Gasp*"utton te#tJ"Su"mit" onclic,J"su"mit" runatJ"ser$er" CI GCformI GC"od'I GChtmlIGscript runatJ"ser$er"I Su" 2ageK/oad if Not 2age. s2ostBac, then l"lE.Te#tJ"The date and time is " M now:; end if End Su" Su" su"mit:s 3s 0">ect, e 3s E$ent3rgs; l"l(.Te#tJ"1ello WorldD"

End Su" GCscriptI GhtmlI G"od'I Gform runatJ"ser$er"I GhBIGasp*la"el idJ"l"lE" runatJ"ser$er" CIGChBI GhBIGasp*la"el idJ"l"l(" runatJ"ser$er" CIGChBI Gasp*"utton te#tJ"Su"mit" onclic,J"su"mit" runatJ"ser$er" CI GCformI GC"od'I GChtmlI

"S+ .NET We$ For

"ll server controls ust a))ear wit'in a Bfor t'e runatDEserverE attri$ute.

C tag( and t'e Bfor

C tag

ust contain

"S+ .NET We$ For

3ll ser$er controls must appear within a GformI tag, and the GformI tag must contain the runatJ"ser$er" attri"ute. The runatJ"ser$er" attri"ute indicates that the form should "e processed on the ser$er. t also indicates that the enclosed controls can "e accessed "' ser$er scripts*

<+orm r#n$t="ser%er"> ...H39( = ser%er controls </+orm>


Note@ The form is alwa's su"mitted to the page itself. f 'ou specif' an action attri"ute, it is ignored. f 'ou omit the method attri"ute, it will "e set to methodJ"post" "' default. 3lso, if 'ou do not specif' the name and id attri"utes, the' are automaticall' assigned "' 3S2.NET. Note@ 3n .asp# page can onl' contain 0NE Gform runatJ"ser$er"I controlD f 'ou select $iew source in an .asp# page containing a form with no name, method, action, or id attri"ute specified, 'ou will see that 3S2 .NET has added these attri"utes to the form. t loo,s something li,e this*

<+orm n$me="'ctl8" method="post" $ct on="p$ge.$sp4" ...some code </+orm>

d="'ctl8">

Su$

itting a For

3 form is most often su"mitted "' clic,ing on a "utton. The Button ser$er control in 3S2 .NET has the following format*

<$sp,6#tton

d=" d" te4t="l$bel" 0n7l c)="s#b" r#n$t="ser%er" />

The id attri"ute defines a uni%ue name for the "utton and the te#t attri"ute assigns a la"el to the "utton. The on6lic, e$ent handler specifies a named su"routine to e#ecute. n the following e#ample we declare a Button control in an .asp# file. 3 "utton clic, runs a su"routine which changes the te#t on the "utton* E#ample

Gscript runatJ"ser$er"I Su" su"mit:Source 3s 0">ect, e 3s E$ent3rgs; "uttonE.Te#tJ"@ou clic,ed meD" End Su" GCscriptI GhtmlI G"od'I Gform runatJ"ser$er"I Gasp*Button idJ""uttonE" Te#tJ"6lic, meD" runatJ"ser$er" 0n6lic,J"su"mit"CI GCformI GC"od'I GChtmlI

"S+ .NET We$ For

"ll server controls ust a))ear wit'in a Bfor t'e runatDEserverE attri$ute.

C tag( and t'e Bfor

C tag

ust contain

"S+ .NET We$ For

3ll ser$er controls must appear within a GformI tag, and the GformI tag must contain the runatJ"ser$er" attri"ute. The runatJ"ser$er" attri"ute indicates that the form should "e processed on the ser$er. t also indicates that the enclosed controls can "e accessed "' ser$er scripts*

<+orm r#n$t="ser%er"> ...H39( = ser%er controls </+orm>


Note@ The form is alwa's su"mitted to the page itself. f 'ou specif' an action attri"ute, it is ignored. f 'ou omit the method attri"ute, it will "e set to methodJ"post" "' default. 3lso, if 'ou do not specif' the name and id attri"utes, the' are automaticall' assigned "' 3S2.NET. Note@ 3n .asp# page can onl' contain 0NE Gform runatJ"ser$er"I controlD

f 'ou select $iew source in an .asp# page containing a form with no name, method, action, or id attri"ute specified, 'ou will see that 3S2 .NET has added these attri"utes to the form. t loo,s something li,e this*

<+orm n$me="'ctl8" method="post" $ct on="p$ge.$sp4" ...some code </+orm>

d="'ctl8">

Su$

itting a For

3 form is most often su"mitted "' clic,ing on a "utton. The Button ser$er control in 3S2 .NET has the following format*

<$sp,6#tton

d=" d" te4t="l$bel" 0n7l c)="s#b" r#n$t="ser%er" />

The id attri"ute defines a uni%ue name for the "utton and the te#t attri"ute assigns a la"el to the "utton. The on6lic, e$ent handler specifies a named su"routine to e#ecute. n the following e#ample we declare a Button control in an .asp# file. 3 "utton clic, runs a su"routine which changes the te#t on the "utton* E#ample

"S+ .NET Maintaining t'e ,iewState

<ou ay save a lot of coding $y For .

aintaining t'e ,iewState of t'e o$>ects in your We$

Maintaining t'e ,iewState


When a form is su"mitted in classic 3S2, all form $alues are cleared. Suppose 'ou ha$e su"mitted a form with a lot of information and the ser$er comes "ac, with an error. @ou will ha$e to go "ac, to the form and correct the information. @ou clic, the "ac, "utton, and what happens.......3// form $alues are 6/E3?E+, and 'ou will ha$e to start all o$er againD The site did not maintain 'our 9iewState. When a form is su"mitted in 3S2 .NET, the form reappears in the "rowser window together with all form $alues. 1ow comeL This is "ecause 3S2 .NET maintains 'our 9iewState. The 9iewState indicates the status of the page when su"mitted to the ser$er. The status is defined through a hidden field placed on each page with a Gform runatJ"ser$er"I control. The source could loo, something li,e this*

<+orm n$me="'ctl8" method="post" $ct on="p$ge.$sp4" < np#t type="h dden" n$me="''.:-WS3/3-"

d="'ctl8">

%$l#e="d>wt<3:80>?@9>-*0As=B67C2ry19pe.g?r52e31DEH<lFG=" /> .....some code </+orm>


Maintaining the 9iewState is the default setting for 3S2.NET We" 5orms. f 'ou want to N0T maintain the 9iewState, include the directi$e GHN 2age Ena"le9iewStateJ"false" HI at the top of an .asp# page or add the attri"ute Ena"le9iewStateJ"false" to an' control. /oo, at the following .asp# file. t demonstrates the "old" wa' to do it. When 'ou clic, on the su"mit "utton, the form $alue will disappear*

<html> <body> <+orm $ct on="demo'cl$ss c$sp.$sp4" method="post"> 5o#r n$me, < np#t type="te4t" n$me="+n$me" s Ae="28"> < np#t type="s#bm t" %$l#e="S#bm t"> </+orm> <% d m +n$me +n$me=ReH#est.Corm!"+n$me"" :+ +n$me<>"" 3hen Response.Wr te!"Hello " ; +n$me ; "!"" -nd :+ %> </body> </html>
E#ample 1ere is the new 3S2 .NET wa'. When 'ou clic, on the su"mit "utton, the form $alue will N0T disappear*

<scr pt r#n$t="ser%er"> S#b s#bm t!sender /s 0b1ect2 e /s -%ent/rgs" lbl*.3e4t="Hello " ; t4t*.3e4t ; "!" -nd S#b </scr pt> <html> <body> <+orm r#n$t="ser%er"> 5o#r n$me, <$sp,3e4t6o4 d="t4t*" r#n$t="ser%er" /> <$sp,6#tton 0n7l c)="s#bm t" 3e4t="S#bm t" r#n$t="ser%er" /> <p><$sp,($bel d="lbl*" r#n$t="ser%er" /></p> </+orm> </body> </html>
E#ample :6lic, $iew source in the right frame of the e#ample to see that 3S2 .NET has added a hidden field in the form to maintain the 9iewState;

"S+ .NET - T'e Text#ox %ontrol

T'e Text#ox control is used to create a text $ox w'ere t'e user can in)ut text.

T'e Text#ox %ontrol


The Te#tBo# control is used to create a te#t "o# where the user can input te#t. The Te#tBo# control's attri"utes and properties are listed in our we" controls reference page. The e#ample "elow demonstrates some of the attri"utes 'ou ma' use with the Te#tBo# control* E#ample

<html> <body> <+orm r#n$t="ser%er"> / b$s c 3e4t6o4, <$sp,3e4t6o4 d="tb*" r#n$t="ser%er" /> <br /><br /> / p$ssword 3e4t6o4, <$sp,3e4t6o4 d="tb2" 3e4t9ode="p$ssword" r#n$t="ser%er" /> <br /><br /> / 3e4t6o4 w th te4t, <$sp,3e4t6o4 d="tbF" 3e4t="Hello World!" r#n$t="ser%er" /> <br /><br /> / m#lt l ne 3e4t6o4, <$sp,3e4t6o4 d="tb3" 3e4t9ode="m#lt l ne" r#n$t="ser%er" /> <br /><br /> / 3e4t6o4 w th he ght, <$sp,3e4t6o4 d="tbI" rows="@" 3e4t9ode="m#lt l ne" r#n$t="ser%er" /> <br /><br /> / 3e4t6o4 w th w dth, <$sp,3e4t6o4 d="tb@" col#mns="38" r#n$t="ser%er" /> </+orm> </body> </html>

"dd a Scri)t
The contents and settings of a Te#tBo# control ma' "e changed "' ser$er scripts when a form is su"mitted. 3 form can "e su"mitted "' clic,ing on a "utton or when a user changes the $alue in the Te#tBo# control. n the following e#ample we declare one Te#tBo# control, one Button control, and one /a"el control in an .asp# file. When the su"mit "utton is triggered, the su"mit su"routine is e#ecuted. The su"mit su"routine writes a te#t to the /a"el control*

<scr pt r#n$t="ser%er"> S#b s#bm t!sender /s 0b1ect2 e /s -%ent/rgs" lbl*.3e4t="5o#r n$me s " ; t4t*.3e4t -nd S#b </scr pt> <html> <body> <+orm r#n$t="ser%er"> -nter yo#r n$me, <$sp,3e4t6o4 d="t4t*" r#n$t="ser%er" /> <$sp,6#tton 0n7l c)="s#bm t" 3e4t="S#bm t" r#n$t="ser%er" /> <p><$sp,($bel d="lbl*" r#n$t="ser%er" /></p> </+orm> </body> </html>
E#ample n the following e#ample we declare one Te#tBo# control and one /a"el control in an .asp# file. When 'ou change the $alue in the Te#tBo# and either clic, outside the Te#tBo# or press the Ta" ,e', the change su"routine is e#ecuted. The su"mit su"routine writes a te#t to the /a"el control*

<scr pt r#n$t="ser%er"> S#b ch$nge!sender /s 0b1ect2 e /s -%ent/rgs" lbl*.3e4t="5o# ch$nged te4t to " ; t4t*.3e4t -nd S#b </scr pt> <html> <body> <+orm r#n$t="ser%er"> -nter yo#r n$me, <$sp,3e4t6o4 d="t4t*" r#n$t="ser%er" te4t="Hello World!" onte4tch$nged="ch$nge" $#topostb$c)="tr#e"/> <p><$sp,($bel d="lbl*" r#n$t="ser%er" /></p> </+orm> </body> </html>

"S+ .NET - T'e #utton %ontrol

T'e #utton control is used to dis)lay a )us' $utton.

T'e #utton %ontrol


The Button control is used to displa' a push "utton. The push "utton ma' "e a su"mit "utton or a command "utton. B' default, this control is a su"mit "utton.

3 su"mit "utton does not ha$e a command name and it posts the page "ac, to the ser$er when it is clic,ed. t is possi"le to write an e$ent handler to control the actions performed when the su"mit "utton is clic,ed. 3 command "utton has a command name and allows 'ou to create multiple Button controls on a page. t is possi"le to write an e$ent handler to control the actions performed when the command "utton is clic,ed. The Button control's attri"utes and properties are listed in our we" controls reference page. The e#ample "elow demonstrates a simple Button control*

<html> <body> <+orm r#n$t="ser%er"> <$sp,6#tton d="b*" 3e4t="S#bm t" r#n$t="ser%er" /> </+orm> </body> </html>

"dd a Scri)t
3 form is most often su"mitted "' clic,ing on a "utton. n the following e#ample we declare one Te#tBo# control, one Button control, and one /a"el control in an .asp# file. When the su"mit "utton is triggered, the su"mit su"routine is e#ecuted. The su"mit su"routine writes a te#t to the /a"el control*

<scr pt r#n$t="ser%er"> S#b s#bm t!sender /s 0b1ect2 e /s -%ent/rgs" lbl*.3e4t="5o#r n$me s " ; t4t*.3e4t -nd S#b </scr pt> <html> <body> <+orm r#n$t="ser%er"> -nter yo#r n$me, <$sp,3e4t6o4 d="t4t*" r#n$t="ser%er" /> <$sp,6#tton 0n7l c)="s#bm t" 3e4t="S#bm t" r#n$t="ser%er" /> <p><$sp,($bel d="lbl*" r#n$t="ser%er" /></p> </+orm> </body> </html>

Gscript runatJ"ser$er"I Su" su"mit:sender 3s 0">ect, e 3s E$ent3rgs; l"lE.Te#tJ"@our name is " M t#tE.Te#t End Su" GCscriptI GhtmlI G"od'I

Gform runatJ"ser$er"I Enter 'our name* Gasp*Te#tBo# idJ"t#tE" runatJ"ser$er" CI Gasp*Button 0n6lic,J"su"mit" Te#tJ"Su"mit" runatJ"ser$er" CI GpIGasp*/a"el idJ"l"lE" runatJ"ser$er" CIGCpI GCformI GC"od'I GChtmlI

"S+ .NET - &ata #inding

We ay use data $inding to fill lists wit' selecta$le ite li!e a data$ase( an 4M. file( or a scri)t.

s fro

an i

)orted data source(

&ata #inding
The following controls are list controls which support data "inding*

asp*?adioButton/ist asp*6hec,Bo#/ist asp*+rop+own/ist asp*/ist"o#

The selecta"le items in each of the a"o$e controls are usuall' defined "' one or more asp*/ist tem controls, li,e this*

<html> <body> <+orm r#n$t="ser%er"> <$sp,R$d o6#tton( st d="co#ntryl st" r#n$t="ser%er"> <$sp,( st:tem %$l#e="<" te4t="<orw$y" /> <$sp,( st:tem %$l#e="S" te4t="Sweden" /> <$sp,( st:tem %$l#e="C" te4t="Cr$nce" /> <$sp,( st:tem %$l#e=":" te4t=":t$ly" /> </$sp,R$d o6#tton( st> </+orm> </body> </html>
1owe$er, with data "inding we ma' use a separate source, li,e a data"ase, an .M/ file, or a script to fill the list with selecta"le items. B' using an imported source, the data is separated from the 1TM/, and an' changes to the items are made in the separate data source. n the ne#t three chapters, we will descri"e how to "ind data from a scripted data source.

"S+ .NET - T'e "rray.ist *$>ect

T'e "rray.ist o$>ect is a collection of ite

s containing a single data value.

Exa

)les

E#ample E ! 3rra'/ist ?adioButton/ist E#ample ( ! 3rra'/ist +rop+own/ist

%reate an "rray.ist
The 3rra'/ist o">ect is a collection of items containing a single data $alue. tems are added to the 3rra'/ist with the 3dd:; method. The following code creates a new 3rra'/ist o">ect named m'countries and four items are added*

<scr pt r#n$t="ser%er"> S#b &$ge'(o$d + <ot &$ge.:s&ost6$c) then d m myco#ntr es=<ew /rr$y( st myco#ntr es./dd!"<orw$y"" myco#ntr es./dd!"Sweden"" myco#ntr es./dd!"Cr$nce"" myco#ntr es./dd!":t$ly"" end + end s#b </scr pt>
B' default, an 3rra'/ist o">ect contains E< entries. 3n 3rra'/ist can "e siAed to its final siAe with the TrimToSiAe:; method*

<scr pt r#n$t="ser%er"> S#b &$ge'(o$d + <ot &$ge.:s&ost6$c) then d m myco#ntr es=<ew /rr$y( st myco#ntr es./dd!"<orw$y"" myco#ntr es./dd!"Sweden"" myco#ntr es./dd!"Cr$nce"" myco#ntr es./dd!":t$ly"" myco#ntr es.3r m3oS Ae!" end + end s#b </scr pt>
3n 3rra'/ist can also "e sorted alpha"eticall' or numericall' with the Sort:; method*

<scr pt r#n$t="ser%er"> S#b &$ge'(o$d + <ot &$ge.:s&ost6$c) then d m myco#ntr es=<ew /rr$y( st

myco#ntr myco#ntr myco#ntr myco#ntr myco#ntr myco#ntr end + end s#b </scr pt>

es./dd!"<orw$y"" es./dd!"Sweden"" es./dd!"Cr$nce"" es./dd!":t$ly"" es.3r m3oS Ae!" es.Sort!"

To sort in re$erse order, appl' the ?e$erse:; method after the Sort:; method*

<scr pt r#n$t="ser%er"> S#b &$ge'(o$d + <ot &$ge.:s&ost6$c) then d m myco#ntr es=<ew /rr$y( st myco#ntr es./dd!"<orw$y"" myco#ntr es./dd!"Sweden"" myco#ntr es./dd!"Cr$nce"" myco#ntr es./dd!":t$ly"" myco#ntr es.3r m3oS Ae!" myco#ntr es.Sort!" myco#ntr es.Re%erse!" end + end s#b </scr pt>

&ata #inding to an "rray.ist


3n 3rra'/ist o">ect ma' automaticall' generate the te#t and $alues to the following controls*

asp*?adioButton/ist asp*6hec,Bo#/ist asp*+rop+own/ist asp*/ist"o#

To "ind data to a ?adioButton/ist control, first create a ?adioButton/ist control :without an' asp*/ist tem elements; in an .asp# page*

<html> <body> <+orm r#n$t="ser%er"> <$sp,R$d o6#tton( st d="rb" r#n$t="ser%er" /> </+orm> </body> </html>
Then add the script that "uilds the list and "inds the $alues in the list to the ?adioButton/ist control*

<scr pt r#n$t="ser%er"> S#b &$ge'(o$d + <ot &$ge.:s&ost6$c) then

d m myco#ntr es=<ew /rr$y( st myco#ntr es./dd!"<orw$y"" myco#ntr es./dd!"Sweden"" myco#ntr es./dd!"Cr$nce"" myco#ntr es./dd!":t$ly"" myco#ntr es.3r m3oS Ae!" myco#ntr es.Sort!" rb.>$t$So#rce=myco#ntr es rb.>$t$6 nd!" end + end s#b </scr pt> <html> <body> <+orm r#n$t="ser%er"> <$sp,R$d o6#tton( st d="rb" r#n$t="ser%er" /> </+orm> </body> </html>
The +ataSource propert' of the ?adioButton/ist control is set to the 3rra'/ist and it defines the data source of the ?adioButton/ist control. The +ataBind:; method of the ?adioButton/ist control "inds the data source with the ?adioButton/ist control. Note@ The data $alues are used as "oth the Te#t and 9alue properties for the control. To add 9alues that are different from the Te#t, use either the 1ashta"le o">ect or the Sorted/ist o">ect.

"S+ .NET - T'e ;as'ta$le *$>ect

T'e ;as'ta$le o$>ect contains ite

s in !eyFvalue )airs.

Exa

)les

E#ample E ! 1ashta"le ?adioButton/ist E#ample ( ! 1ashta"le ?adio"utton/ist E#ample B ! 1ashta"le +rop+own/ist

%reate a ;as'ta$le
The 1ashta"le o">ect contains items in ,e'C$alue pairs. The ,e's are used as inde#es, and $er' %uic, searches can "e made for $alues "' searching through their ,e's. tems are added to the 1ashta"le with the 3dd:; method. The following code creates a 1ashta"le named m'countries and four elements are added*

<scr pt r#n$t="ser%er"> S#b &$ge'(o$d

+ <ot &$ge.:s&ost6$c) then d m myco#ntr es=<ew H$sht$ble myco#ntr es./dd!"<"2"<orw$y"" myco#ntr es./dd!"S"2"Sweden"" myco#ntr es./dd!"C"2"Cr$nce"" myco#ntr es./dd!":"2":t$ly"" end + end s#b </scr pt>

&ata #inding
3 1ashta"le o">ect ma' automaticall' generate the te#t and $alues to the following controls*

asp*?adioButton/ist asp*6hec,Bo#/ist asp*+rop+own/ist asp*/ist"o#

To "ind data to a ?adioButton/ist control, first create a ?adioButton/ist control :without an' asp*/ist tem elements; in an .asp# page*

<html> <body> <+orm r#n$t="ser%er"> <$sp,R$d o6#tton( st d="rb" r#n$t="ser%er" /#to&ost6$c)="3r#e" /> </+orm> </body> </html>
Then add the script that "uilds the list*

<scr pt r#n$t="ser%er"> s#b &$ge'(o$d + <ot &$ge.:s&ost6$c) then d m myco#ntr es=<ew H$sht$ble myco#ntr es./dd!"<"2"<orw$y"" myco#ntr es./dd!"S"2"Sweden"" myco#ntr es./dd!"C"2"Cr$nce"" myco#ntr es./dd!":"2":t$ly"" rb.>$t$So#rce=myco#ntr es rb.>$t$.$l#eC eld="Jey" rb.>$t$3e4tC eld=".$l#e" rb.>$t$6 nd!" end + end s#b </scr pt> <html> <body> <+orm r#n$t="ser%er"> <$sp,R$d o6#tton( st d="rb" r#n$t="ser%er" /#to&ost6$c)="3r#e" /> </+orm>

</body> </html>
Then we add a su" routine to "e e#ecuted when the user clic,s on an item in the ?adioButton/ist control. When a radio "utton is clic,ed, a te#t will appear in a la"el*

<scr pt r#n$t="ser%er"> s#b &$ge'(o$d + <ot &$ge.:s&ost6$c) then d m myco#ntr es=<ew H$sht$ble myco#ntr es./dd!"<"2"<orw$y"" myco#ntr es./dd!"S"2"Sweden"" myco#ntr es./dd!"C"2"Cr$nce"" myco#ntr es./dd!":"2":t$ly"" rb.>$t$So#rce=myco#ntr es rb.>$t$.$l#eC eld="Jey" rb.>$t$3e4tC eld=".$l#e" rb.>$t$6 nd!" end + end s#b s#b d spl$y9ess$ge!s $s 0b1ect2e /s -%ent/rgs" lbl*.te4t="5o#r +$%or te co#ntry s, " ; rb.Selected:tem.3e4t end s#b </scr pt> <html> <body> <+orm r#n$t="ser%er"> <$sp,R$d o6#tton( st d="rb" r#n$t="ser%er" /#to&ost6$c)="3r#e" onSelected:nde47h$nged="d spl$y9ess$ge" /> <p><$sp,l$bel d="lbl*" r#n$t="ser%er" /></p> </+orm> </body> </html>
Note@ @ou cannot choose the sort order of the items added to the 1ashta"le. To sort items alpha"eticall' or numericall', use the Sorted/ist o">ect.

Gscript runatJ"ser$er"I su" 2ageK/oad if Not 2age. s2ostBac, then dim m'countriesJNew 1ashta"le m'countries.3dd:"N","Norwa'"; m'countries.3dd:"S","Sweden"; m'countries.3dd:"5","5rance"; m'countries.3dd:" "," tal'"; r".+ataSourceJm'countries r".+ata9alue5ieldJ"Fe'" r".+ataTe#t5ieldJ"9alue" r".+ataBind:; end if end su" su" displa'Message:s as 0">ect,e 3s E$ent3rgs; l"lE.te#tJ"@our fa$orite countr' is* " M r".Selected tem.Te#t end su"

GCscriptI GhtmlI G"od'I Gform runatJ"ser$er"I Gasp*?adioButton/ist idJ"r"" runatJ"ser$er" 3uto2ostBac,J"True" onSelected nde#6hangedJ"displa'Message" CI GpIGasp*la"el idJ"l"lE" runatJ"ser$er" CIGCpI GCformI GC"od'I GChtmlI Gscript runatJ"ser$er"I su" 2ageK/oad if Not 2age. s2ostBac, then dim na$igateJNew 1ashta"le na$igate.3dd:"?adioButton/ist","controlKradio"uttonlist.asp"; na$igate.3dd:"6hec,Bo#/ist","controlKchec,"o#list.asp"; na$igate.3dd:"+rop+own/ist","controlKdropdownlist.asp"; na$igate.3dd:"/istBo#","controlKlist"o#.asp"; r".+ataSourceJna$igate r".+ata9alue5ieldJ"9alue" r".+ataTe#t5ieldJ"Fe'" r".+ataBind:; end if end su" su" na$igate:s as 0">ect, e 3s E$ent3rgs; response.redirect:r".Selected tem.9alue; end su" GCscriptI GhtmlI G"od'I Gform runatJ"ser$er"I Gasp*?adioButton/ist idJ"r"" runatJ"ser$er" 3uto2ostBac,J"True" onSelected nde#6hangedJ"na$igate" CI GCformI GC"od'I GChtmlI Gscript runatJ"ser$er"I su" 2ageK/oad if Not 2age. s2ostBac, then dim m'countriesJNew 1ashta"le m'countries.3dd:"N","Norwa'"; m'countries.3dd:"S","Sweden"; m'countries.3dd:"5","5rance"; m'countries.3dd:" "," tal'";

dd.+ataSourceJm'countries dd.+ata9alue5ieldJ"Fe'" dd.+ataTe#t5ieldJ"9alue" dd.+ataBind:; end if end su" su" displa'Message:s as 0">ect,e 3s E$ent3rgs; l"lE.te#tJ"@our fa$orite countr' is* " M dd.Selected tem.Te#t end su" GCscriptI GhtmlI G"od'I Gform runatJ"ser$er"I Gasp*+rop+own/ist idJ"dd" runatJ"ser$er" 3uto2ostBac,J"True" onSelected nde#6hangedJ"displa'Message" CI GpIGasp*la"el idJ"l"lE" runatJ"ser$er" CIGCpI GCformI GC"od'I GChtmlI

"S+ .NET - T'e Sorted.ist *$>ect

T'e Sorted.ist o$>ect co ;as'ta$le o$>ect.

$ines t'e features of $ot' t'e "rray.ist o$>ect and t'e

Exa

)les

E#ample E ! Sorted/ist ?adioButton/ist E#ample ( ! Sorted/ist ?adio"utton/ist E#ample B ! Sorted/ist +rop+own/ist

T'e Sorted.ist *$>ect


The Sorted/ist o">ect contains items in ,e'C$alue pairs. 3 Sorted/ist o">ect automaticall' sort the items in alpha"etic or numeric order. tems are added to the Sorted/ist with the 3dd:; method. 3 Sorted/ist can "e siAed to its final siAe with the TrimToSiAe:; method. The following code creates a Sorted/ist named m'countries and four elements are added*

<scr pt r#n$t="ser%er"> s#b &$ge'(o$d + <ot &$ge.:s&ost6$c) then d m myco#ntr es=<ew Sorted( st myco#ntr es./dd!"<"2"<orw$y"" myco#ntr es./dd!"S"2"Sweden"" myco#ntr es./dd!"C"2"Cr$nce"" myco#ntr es./dd!":"2":t$ly"" end + end s#b </scr pt>

&ata #inding
3 Sorted/ist o">ect ma' automaticall' generate the te#t and $alues to the following controls*

asp*?adioButton/ist asp*6hec,Bo#/ist asp*+rop+own/ist asp*/ist"o#

To "ind data to a ?adioButton/ist control, first create a ?adioButton/ist control :without an' asp*/ist tem elements; in an .asp# page*

<html> <body> <+orm r#n$t="ser%er"> <$sp,R$d o6#tton( st d="rb" r#n$t="ser%er" /#to&ost6$c)="3r#e" /> </+orm> </body> </html>
Then add the script that "uilds the list*

<scr pt r#n$t="ser%er"> s#b &$ge'(o$d + <ot &$ge.:s&ost6$c) then d m myco#ntr es=<ew Sorted( st myco#ntr es./dd!"<"2"<orw$y"" myco#ntr es./dd!"S"2"Sweden"" myco#ntr es./dd!"C"2"Cr$nce"" myco#ntr es./dd!":"2":t$ly"" rb.>$t$So#rce=myco#ntr es rb.>$t$.$l#eC eld="Jey" rb.>$t$3e4tC eld=".$l#e" rb.>$t$6 nd!" end + end s#b </scr pt> <html> <body> <+orm r#n$t="ser%er"> <$sp,R$d o6#tton( st d="rb" r#n$t="ser%er"

/#to&ost6$c)="3r#e" /> </+orm> </body> </html>


Then we add a su" routine to "e e#ecuted when the user clic,s on an item in the ?adioButton/ist control. When a radio "utton is clic,ed, a te#t will appear in a la"el*

<scr pt r#n$t="ser%er"> s#b &$ge'(o$d + <ot &$ge.:s&ost6$c) then d m myco#ntr es=<ew Sorted( st myco#ntr es./dd!"<"2"<orw$y"" myco#ntr es./dd!"S"2"Sweden"" myco#ntr es./dd!"C"2"Cr$nce"" myco#ntr es./dd!":"2":t$ly"" rb.>$t$So#rce=myco#ntr es rb.>$t$.$l#eC eld="Jey" rb.>$t$3e4tC eld=".$l#e" rb.>$t$6 nd!" end + end s#b s#b d spl$y9ess$ge!s $s 0b1ect2e /s -%ent/rgs" lbl*.te4t="5o#r +$%or te co#ntry s, " ; rb.Selected:tem.3e4t end s#b </scr pt> <html> <body> <+orm r#n$t="ser%er"> <$sp,R$d o6#tton( st d="rb" r#n$t="ser%er" /#to&ost6$c)="3r#e" onSelected:nde47h$nged="d spl$y9ess$ge" /> <p><$sp,l$bel d="lbl*" r#n$t="ser%er" /></p> </+orm> </body> </html>

"S+ .NET - 4M. Files

We can $ind an 4M. file to a list control.

Exa

)les

E#ample E ! .M/ ?adio"utton/ist

"n 4M. File


1ere is an .M/ file named "countries.#ml"*

<K4ml %ers on="*.8" encod ng=":S0LMM@EL*"K> <co#ntr es> <co#ntry> <te4t><orw$y</te4t> <%$l#e><</%$l#e> </co#ntry> <co#ntry> <te4t>Sweden</te4t> <%$l#e>S</%$l#e> </co#ntry> <co#ntry> <te4t>Cr$nce</te4t> <%$l#e>C</%$l#e> </co#ntry> <co#ntry> <te4t>:t$ly</te4t> <%$l#e>:</%$l#e> </co#ntry> </co#ntr es>
Ta,e a loo, at the .M/ file* countries.#ml

#ind a &ataSet to a .ist %ontrol


5irst, import the "S'stem.+ata" namespace. We need this namespace to wor, with +ataSet o">ects. nclude the following directi$e at the top of an .asp# page*

<%N :mport <$mesp$ce="System.>$t$" %>


Ne#t, create a +ataSet for the .M/ file and load the .M/ file into the +ataSet when the page is first loaded*

<scr pt r#n$t="ser%er"> s#b &$ge'(o$d + <ot &$ge.:s&ost6$c) then d m myco#ntr es=<ew >$t$Set myco#ntr es.Re$dOml!9$p&$th!"co#ntr es.4ml""" end + end s#b
To "ind the +ataSet to a ?adioButton/ist control, first create a ?adioButton/ist control :without an' asp*/ist tem elements; in an .asp# page*

<html> <body> <+orm r#n$t="ser%er"> <$sp,R$d o6#tton( st d="rb" r#n$t="ser%er" /#to&ost6$c)="3r#e" /> </+orm> </body> </html>
Then add the script that "uilds the .M/ +ataSet*

<%N :mport <$mesp$ce="System.>$t$" %> <scr pt r#n$t="ser%er"> s#b &$ge'(o$d + <ot &$ge.:s&ost6$c) then d m myco#ntr es=<ew >$t$Set myco#ntr es.Re$dOml!9$p&$th!"co#ntr es.4ml""" rb.>$t$So#rce=myco#ntr es rb.>$t$.$l#eC eld="%$l#e" rb.>$t$3e4tC eld="te4t" rb.>$t$6 nd!" end + end s#b </scr pt> <html> <body> <+orm r#n$t="ser%er"> <$sp,R$d o6#tton( st d="rb" r#n$t="ser%er" /#to&ost6$c)="3r#e" onSelected:nde47h$nged="d spl$y9ess$ge" /> </+orm> </body> </html>
Then we add a su" routine to "e e#ecuted when the user clic,s on an item in the ?adioButton/ist control. When a radio "utton is clic,ed, a te#t will appear in a la"el*

<%N :mport <$mesp$ce="System.>$t$" %> <scr pt r#n$t="ser%er"> s#b &$ge'(o$d + <ot &$ge.:s&ost6$c) then d m myco#ntr es=<ew >$t$Set myco#ntr es.Re$dOml!9$p&$th!"co#ntr es.4ml""" rb.>$t$So#rce=myco#ntr es rb.>$t$.$l#eC eld="%$l#e" rb.>$t$3e4tC eld="te4t" rb.>$t$6 nd!" end + end s#b s#b d spl$y9ess$ge!s $s 0b1ect2e /s -%ent/rgs" lbl*.te4t="5o#r +$%or te co#ntry s, " ; rb.Selected:tem.3e4t end s#b </scr pt> <html> <body> <+orm r#n$t="ser%er"> <$sp,R$d o6#tton( st d="rb" r#n$t="ser%er" /#to&ost6$c)="3r#e" onSelected:nde47h$nged="d spl$y9ess$ge" /> <p><$sp,l$bel d="lbl*" r#n$t="ser%er" /></p> </+orm> </body> </html>

"S+ .NET - T'e :e)eater %ontrol

T'e :e)eater control is used to dis)lay a re)eated list of ite control.

s t'at are $ound to t'e

Exa

)les

?epeater control ?epeater control with G3lternating temTemplateI ?epeater control with GSeparatorTemplateI

#ind a &ataSet to a :e)eater %ontrol


The ?epeater control is used to displa' a repeated list of items that are "ound to the control. The ?epeater control ma' "e "ound to a data"ase ta"le, an .M/ file, or another list of items. 1ere we will show how to "ind an .M/ file to a ?epeater control. We will use the following .M/ file in our e#amples :"cdcatalog.#ml";*

<K4ml %ers on="*.8" encod ng=":S0LMM@EL*"K> <c$t$log> <cd> <t tle>-mp re 6#rlesH#e</t tle> <$rt st>6ob >yl$n</$rt st> <co#ntry>?S/</co#ntry> <comp$ny>7ol#mb $</comp$ny> <pr ce>*8.E8</pr ce> <ye$r>*EM@</ye$r> </cd> <cd> <t tle>H de yo#r he$rt</t tle> <$rt st>6onn e 3yler</$rt st> <co#ntry>?J</co#ntry> <comp$ny>76S Records</comp$ny> <pr ce>E.E8</pr ce> <ye$r>*EMM</ye$r> </cd> <cd> <t tle>Pre$test H ts</t tle> <$rt st>>olly &$rton</$rt st> <co#ntry>?S/</co#ntry> <comp$ny>R7/</comp$ny> <pr ce>E.E8</pr ce> <ye$r>*EM2</ye$r> </cd> <cd> <t tle>St ll got the bl#es</t tle> <$rt st>P$ry 9oore</$rt st> <co#ntry>?J</co#ntry> <comp$ny>. rg n records</comp$ny> <pr ce>*8.28</pr ce> <ye$r>*EE8</ye$r> </cd> <cd> <t tle>-ros</t tle>

<$rt st>-ros R$m$AAott </$rt st> <co#ntry>-?</co#ntry> <comp$ny>69P</comp$ny> <pr ce>E.E8</pr ce> <ye$r>*EED</ye$r> </cd> </c$t$log>
Ta,e a loo, at the .M/ file* cdcatalog.#ml 5irst, import the "S'stem.+ata" namespace. We need this namespace to wor, with +ataSet o">ects. nclude the following directi$e at the top of an .asp# page*

<%N :mport <$mesp$ce="System.>$t$" %>


Ne#t, create a +ataSet for the .M/ file and load the .M/ file into the +ataSet when the page is first loaded*

<scr pt r#n$t="ser%er"> s#b &$ge'(o$d + <ot &$ge.:s&ost6$c) then d m mycdc$t$log=<ew >$t$Set mycdc$t$log.Re$dOml!9$p&$th!"cdc$t$log.4ml""" end + end s#b
Then we create a ?epeater control in an .asp# page. The contents of the G1eaderTemplateI element are rendered first and onl' once within the output, then the contents of the G temTemplateI element are repeated for each "record" in the +ataSet, and last, the contents of the G5ooterTemplateI element are rendered once within the output*

<html> <body> <+orm r#n$t="ser%er"> <$sp,Repe$ter d="cdc$t$log" r#n$t="ser%er"> <He$der3empl$te> ... </He$der3empl$te> <:tem3empl$te> ... </:tem3empl$te> <Cooter3empl$te> ... </Cooter3empl$te> </$sp,Repe$ter> </+orm> </html> </body>
Then we add the script that creates the +ataSet and "inds the m'cdcatalog +ataSet to the ?epeater control. We also fill the ?epeater control with 1TM/ tags and "ind the data items to the cells in theG temTemplateI section with the GH86ontainer.+ata tem:"fieldname";HI method*

<%N :mport <$mesp$ce="System.>$t$" %>

<scr pt r#n$t="ser%er"> s#b &$ge'(o$d + <ot &$ge.:s&ost6$c) then d m mycdc$t$log=<ew >$t$Set mycdc$t$log.Re$dOml!9$p&$th!"cdc$t$log.4ml""" cdc$t$log.>$t$So#rce=mycdc$t$log cdc$t$log.>$t$6 nd!" end + end s#b </scr pt> <html> <body> <+orm r#n$t="ser%er"> <$sp,Repe$ter d="cdc$t$log" r#n$t="ser%er"> <He$der3empl$te> <t$ble border="*" w dth="*88%"> <tr> <th>3 tle</th> <th>/rt st</th> <th>7o#ntry</th> <th>7omp$ny</th> <th>&r ce</th> <th>5e$r</th> </tr> </He$der3empl$te> <:tem3empl$te> <tr> <td><%Q7ont$ ner.>$t$:tem!"t tle""%></td> <td><%Q7ont$ ner.>$t$:tem!"$rt st""%></td> <td><%Q7ont$ ner.>$t$:tem!"co#ntry""%></td> <td><%Q7ont$ ner.>$t$:tem!"comp$ny""%></td> <td><%Q7ont$ ner.>$t$:tem!"pr ce""%></td> <td><%Q7ont$ ner.>$t$:tem!"ye$r""%></td> </tr> </:tem3empl$te> <Cooter3empl$te> </t$ble> </Cooter3empl$te> </$sp,Repe$ter> </+orm> </html> </body>

3sing t'e B"lternatingIte

Te

)lateC

@ou can add an G3lternating temTemplateI element after the G temTemplateI element to descri"e the appearance of alternating rows of output. n the following e#ample each other row in the ta"le will "e displa'ed in a light gre' color*

<%N :mport <$mesp$ce="System.>$t$" %> <scr pt r#n$t="ser%er"> s#b &$ge'(o$d + <ot &$ge.:s&ost6$c) then d m mycdc$t$log=<ew >$t$Set mycdc$t$log.Re$dOml!9$p&$th!"cdc$t$log.4ml""" cdc$t$log.>$t$So#rce=mycdc$t$log cdc$t$log.>$t$6 nd!"

end + end s#b </scr pt> <html> <body> <+orm r#n$t="ser%er"> <$sp,Repe$ter d="cdc$t$log" r#n$t="ser%er"> <He$der3empl$te> <t$ble border="*" w dth="*88%"> <tr> <th>3 tle</th> <th>/rt st</th> <th>7o#ntry</th> <th>7omp$ny</th> <th>&r ce</th> <th>5e$r</th> </tr> </He$der3empl$te> <:tem3empl$te> <tr> <td><%Q7ont$ ner.>$t$:tem!"t tle""%></td> <td><%Q7ont$ ner.>$t$:tem!"$rt st""%></td> <td><%Q7ont$ ner.>$t$:tem!"co#ntry""%></td> <td><%Q7ont$ ner.>$t$:tem!"comp$ny""%></td> <td><%Q7ont$ ner.>$t$:tem!"pr ce""%></td> <td><%Q7ont$ ner.>$t$:tem!"ye$r""%></td> </tr> </:tem3empl$te> </ltern$t ng:tem3empl$te> <tr bgcolor="QeMeMeM"> <td><%Q7ont$ ner.>$t$:tem!"t tle""%></td> <td><%Q7ont$ ner.>$t$:tem!"$rt st""%></td> <td><%Q7ont$ ner.>$t$:tem!"co#ntry""%></td> <td><%Q7ont$ ner.>$t$:tem!"comp$ny""%></td> <td><%Q7ont$ ner.>$t$:tem!"pr ce""%></td> <td><%Q7ont$ ner.>$t$:tem!"ye$r""%></td> </tr> <//ltern$t ng:tem3empl$te> <Cooter3empl$te> </t$ble> </Cooter3empl$te> </$sp,Repe$ter> </+orm> </html> </body>

3sing t'e BSe)aratorTe

)lateC

The GSeparatorTemplateI element can "e used to descri"e a separator "etween each record. The following e#ample inserts a horiAontal line "etween each ta"le row*

<%N :mport <$mesp$ce="System.>$t$" %> <scr pt r#n$t="ser%er"> s#b &$ge'(o$d + <ot &$ge.:s&ost6$c) then d m mycdc$t$log=<ew >$t$Set mycdc$t$log.Re$dOml!9$p&$th!"cdc$t$log.4ml"""

cdc$t$log.>$t$So#rce=mycdc$t$log cdc$t$log.>$t$6 nd!" end + end s#b </scr pt> <html> <body> <+orm r#n$t="ser%er"> <$sp,Repe$ter d="cdc$t$log" r#n$t="ser%er"> <He$der3empl$te> <t$ble border="8" w dth="*88%"> <tr> <th>3 tle</th> <th>/rt st</th> <th>7o#ntry</th> <th>7omp$ny</th> <th>&r ce</th> <th>5e$r</th> </tr> </He$der3empl$te> <:tem3empl$te> <tr> <td><%Q7ont$ ner.>$t$:tem!"t tle""%></td> <td><%Q7ont$ ner.>$t$:tem!"$rt st""%></td> <td><%Q7ont$ ner.>$t$:tem!"co#ntry""%></td> <td><%Q7ont$ ner.>$t$:tem!"comp$ny""%></td> <td><%Q7ont$ ner.>$t$:tem!"pr ce""%></td> <td><%Q7ont$ ner.>$t$:tem!"ye$r""%></td> </tr> </:tem3empl$te> <Sep$r$tor3empl$te> <tr> <td colsp$n="I"><hr /></td> </tr> </Sep$r$tor3empl$te> <Cooter3empl$te> </t$ble> </Cooter3empl$te> </$sp,Repe$ter> </+orm> </html> </body>

"S+ .NET - T'e &ata.ist %ontrol

T'e &ata.ist control is( li!e t'e :e)eater control( used to dis)lay a re)eated list of ite s t'at are $ound to t'e control. ;owever( t'e &ata.ist control adds a ta$le around t'e data ite s $y default.

Exa

)les

+ata/ist control

+ata/ist control with st'les +ata/ist control with G3lternating temTemplateI

#ind a &ataSet to a &ata.ist %ontrol


The +ata/ist control is, li,e the ?epeater control, used to displa' a repeated list of items that are "ound to the control. 1owe$er, the +ata/ist control adds a ta"le around the data items "' default. The +ata/ist control ma' "e "ound to a data"ase ta"le, an .M/ file, or another list of items. 1ere we will show how to "ind an .M/ file to a +ata/ist control. We will use the following .M/ file in our e#amples :"cdcatalog.#ml";*

<K4ml %ers on="*.8" encod ng=":S0LMM@EL*"K> <c$t$log> <cd> <t tle>-mp re 6#rlesH#e</t tle> <$rt st>6ob >yl$n</$rt st> <co#ntry>?S/</co#ntry> <comp$ny>7ol#mb $</comp$ny> <pr ce>*8.E8</pr ce> <ye$r>*EM@</ye$r> </cd> <cd> <t tle>H de yo#r he$rt</t tle> <$rt st>6onn e 3yler</$rt st> <co#ntry>?J</co#ntry> <comp$ny>76S Records</comp$ny> <pr ce>E.E8</pr ce> <ye$r>*EMM</ye$r> </cd> <cd> <t tle>Pre$test H ts</t tle> <$rt st>>olly &$rton</$rt st> <co#ntry>?S/</co#ntry> <comp$ny>R7/</comp$ny> <pr ce>E.E8</pr ce> <ye$r>*EM2</ye$r> </cd> <cd> <t tle>St ll got the bl#es</t tle> <$rt st>P$ry 9oore</$rt st> <co#ntry>?J</co#ntry> <comp$ny>. rg n records</comp$ny> <pr ce>*8.28</pr ce> <ye$r>*EE8</ye$r> </cd> <cd> <t tle>-ros</t tle> <$rt st>-ros R$m$AAott </$rt st> <co#ntry>-?</co#ntry> <comp$ny>69P</comp$ny> <pr ce>E.E8</pr ce> <ye$r>*EED</ye$r> </cd> </c$t$log>

Ta,e a loo, at the .M/ file* cdcatalog.#ml 5irst, import the "S'stem.+ata" namespace. We need this namespace to wor, with +ataSet o">ects. nclude the following directi$e at the top of an .asp# page*

<%N :mport <$mesp$ce="System.>$t$" %>


Ne#t, create a +ataSet for the .M/ file and load the .M/ file into the +ataSet when the page is first loaded*

<scr pt r#n$t="ser%er"> s#b &$ge'(o$d + <ot &$ge.:s&ost6$c) then d m mycdc$t$log=<ew >$t$Set mycdc$t$log.Re$dOml!9$p&$th!"cdc$t$log.4ml""" end + end s#b
Then we create a +ata/ist in an .asp# page. The contents of the G1eaderTemplateI element are rendered first and onl' once within the output, then the contents of the G temTemplateI element are repeated for each "record" in the +ataSet, and last, the contents of the G5ooterTemplateI element are rendered once within the output*

<html> <body> <+orm r#n$t="ser%er"> <$sp,>$t$( st d="cdc$t$log" r#n$t="ser%er"> <He$der3empl$te> ... </He$der3empl$te> <:tem3empl$te> ... </:tem3empl$te> <Cooter3empl$te> ... </Cooter3empl$te> </$sp,>$t$( st> </+orm> </body> </html>
Then we add the script that creates the +ataSet and "inds the m'cdcatalog +ataSet to the +ata/ist control. We also fill the +ata/ist control with a G1eaderTemplateI that contains the header of the ta"le, an G temTemplateI that contains the data items to displa', and a G5ooterTemplateI that contains a te#t. Note that the gridlines attri"ute of the +ata/ist is set to ""oth" to displa' ta"le "orders*

<%N :mport <$mesp$ce="System.>$t$" %> <scr pt r#n$t="ser%er"> s#b &$ge'(o$d + <ot &$ge.:s&ost6$c) then d m mycdc$t$log=<ew >$t$Set mycdc$t$log.Re$dOml!9$p&$th!"cdc$t$log.4ml""" cdc$t$log.>$t$So#rce=mycdc$t$log cdc$t$log.>$t$6 nd!"

end + end s#b </scr pt> <html> <body> <+orm r#n$t="ser%er"> <$sp,>$t$( st d="cdc$t$log" gr dl nes="both" r#n$t="ser%er"> <He$der3empl$te> 9y 7> 7$t$log </He$der3empl$te> <:tem3empl$te> "<%Q7ont$ ner.>$t$:tem!"t tle""%>" o+ <%Q7ont$ ner.>$t$:tem!"$rt st""%> L R<%Q7ont$ ner.>$t$:tem!"pr ce""%> </:tem3empl$te> <Cooter3empl$te> 7opyr ght Hege Re+snes </Cooter3empl$te> </$sp,>$t$( st> </+orm> </body> </html>

3sing Styles
@ou can also add st'les to the +ata/ist control to ma,e the output more fanc'*

<%N :mport <$mesp$ce="System.>$t$" %> <scr pt r#n$t="ser%er"> s#b &$ge'(o$d + <ot &$ge.:s&ost6$c) then d m mycdc$t$log=<ew >$t$Set mycdc$t$log.Re$dOml!9$p&$th!"cdc$t$log.4ml""" cdc$t$log.>$t$So#rce=mycdc$t$log cdc$t$log.>$t$6 nd!" end + end s#b </scr pt> <html> <body> <+orm r#n$t="ser%er"> <$sp,>$t$( st d="cdc$t$log" r#n$t="ser%er" cellp$dd ng="2" cellsp$c ng="2" borderstyle=" nset" b$c)color="QeMeMeM" w dth="*88%" he$derstyleL+ontLn$me=".erd$n$" he$derstyleL+ontLs Ae="*2pt" he$derstyleLhor Aont$l$l gn="center" he$derstyleL+ontLbold="tr#e" temstyleLb$c)color="QDDMMEE" temstyleL+orecolor="Q++++++" +ooterstyleL+ontLs Ae="Ept" +ooterstyleL+ontL t$l c="tr#e">

<He$der3empl$te> 9y 7> 7$t$log </He$der3empl$te> <:tem3empl$te> "<%Q7ont$ ner.>$t$:tem!"t tle""%>" o+ <%Q7ont$ ner.>$t$:tem!"$rt st""%> L R<%Q7ont$ ner.>$t$:tem!"pr ce""%> </:tem3empl$te> <Cooter3empl$te> 7opyr ght Hege Re+snes </Cooter3empl$te> </$sp,>$t$( st> </+orm> </body> </html>

3sing t'e B"lternatingIte

Te

)lateC

@ou can add an G3lternating temTemplateI element after the G temTemplateI element to descri"e the appearance of alternating rows of output. @ou ma' st'le the data in the G3lternating temTemplateI section within the +ata/ist control*

<%N :mport <$mesp$ce="System.>$t$" %> <scr pt r#n$t="ser%er"> s#b &$ge'(o$d + <ot &$ge.:s&ost6$c) then d m mycdc$t$log=<ew >$t$Set mycdc$t$log.Re$dOml!9$p&$th!"cdc$t$log.4ml""" cdc$t$log.>$t$So#rce=mycdc$t$log cdc$t$log.>$t$6 nd!" end + end s#b </scr pt> <html> <body> <+orm r#n$t="ser%er"> <$sp,>$t$( st d="cdc$t$log" r#n$t="ser%er" cellp$dd ng="2" cellsp$c ng="2" borderstyle=" nset" b$c)color="QeMeMeM" w dth="*88%" he$derstyleL+ontLn$me=".erd$n$" he$derstyleL+ontLs Ae="*2pt" he$derstyleLhor Aont$l$l gn="center" he$derstyleL+ontLbold="3r#e" temstyleLb$c)color="QDDMMEE" temstyleL+orecolor="Q++++++" $ltern$t ng temstyleLb$c)color="QeMeMeM" $ltern$t ng temstyleL+orecolor="Q888888" +ooterstyleL+ontLs Ae="Ept" +ooterstyleL+ontL t$l c="3r#e"> <He$der3empl$te> 9y 7> 7$t$log </He$der3empl$te> <:tem3empl$te>

"<%Q7ont$ ner.>$t$:tem!"t tle""%>" o+ <%Q7ont$ ner.>$t$:tem!"$rt st""%> L R<%Q7ont$ ner.>$t$:tem!"pr ce""%> </:tem3empl$te> </ltern$t ng:tem3empl$te> "<%Q7ont$ ner.>$t$:tem!"t tle""%>" o+ <%Q7ont$ ner.>$t$:tem!"$rt st""%> L R<%Q7ont$ ner.>$t$:tem!"pr ce""%> <//ltern$t ng:tem3empl$te> <Cooter3empl$te> ;copyS Hege Re+snes </Cooter3empl$te> </$sp,>$t$( st> </+orm> </body> </html>

"S+ .NET - &ata$ase %onnection

"&* .NET is a )art of t'e .NET Fra ewor! and it is used to 'andle data access. Wit' "&* .NET you can wor! wit' data$ases.

Exa

)les

+ata"ase connection ! Bind to a ?epeater control +ata"ase connection ! Bind to a +ata/ist control

W'at is "&* .NET2


3+0 .NET is a part of the .NET 5ramewor, 3+0 .NET consists of a set of classes used to handle data access 3+0 .NET is entirel' "ased on .M/ 3+0 .NET has, unli,e 3+0, no ?ecordset o">ect

%reate a &ata$ase %onnection


We are going to use the Northwind data"ase in our e#amples. 5irst, import the "S'stem.+ata.0le+"" namespace. We need this namespace to wor, with Microsoft 3ccess and other 0/E +B data"ase pro$iders. We will create the connection to the data"ase in the 2ageK/oad su"routine. We create a d"conn $aria"le as a new 0le+"6onnection class with a connection string which identifies the 0/E +B pro$ider and the location of the data"ase. Then we open the data"ase connection*

<%N :mport <$mesp$ce="System.>$t$.0le>b" %> <scr pt r#n$t="ser%er">

s#b &$ge'(o$d d m dbconn dbconn=<ew 0le>b7onnect on!"&ro% der=9 croso+t.Tet.0(->6.F.8S d$t$ so#rce=" ; ser%er.m$pp$th!"northw nd.mdb""" dbconn.0pen!" end s#b </scr pt>
Note@ The connection string must "e a continuous string without a line "rea,D

%reate a &ata$ase %o

and

To specif' the records to retrie$e from the data"ase, we will create a d"comm $aria"le as a new 0le+"6ommand class. The 0le+"6ommand class is for issuing S=/ %ueries against data"ase ta"les*

<%N :mport <$mesp$ce="System.>$t$.0le>b" %> <scr pt r#n$t="ser%er"> s#b &$ge'(o$d d m dbconn2sHl2dbcomm dbconn=<ew 0le>b7onnect on!"&ro% der=9 croso+t.Tet.0(->6.F.8S d$t$ so#rce=" ; ser%er.m$pp$th!"northw nd.mdb""" dbconn.0pen!" sHl="S-(-73 U CR09 c#stomers" dbcomm=<ew 0le>b7omm$nd!sHl2dbconn" end s#b </scr pt>

%reate a &ata:eader
The 0le+"+ata?eader class is used to read a stream of records from a data source. 3 +ata?eader is created "' calling the E#ecute?eader method of the 0le+"6ommand o">ect*

<%N :mport <$mesp$ce="System.>$t$.0le>b" %> <scr pt r#n$t="ser%er"> s#b &$ge'(o$d d m dbconn2sHl2dbcomm2dbre$d dbconn=<ew 0le>b7onnect on!"&ro% der=9 croso+t.Tet.0(->6.F.8S d$t$ so#rce=" ; ser%er.m$pp$th!"northw nd.mdb""" dbconn.0pen!" sHl="S-(-73 U CR09 c#stomers" dbcomm=<ew 0le>b7omm$nd!sHl2dbconn" dbre$d=dbcomm.-4ec#teRe$der!" end s#b </scr pt>

#ind to a :e)eater %ontrol


Then we "ind the +ata?eader to a ?epeater control*

<%N :mport <$mesp$ce="System.>$t$.0le>b" %> <scr pt r#n$t="ser%er"> s#b &$ge'(o$d

d m dbconn2sHl2dbcomm2dbre$d dbconn=<ew 0le>b7onnect on!"&ro% der=9 croso+t.Tet.0(->6.F.8S d$t$ so#rce=" ; ser%er.m$pp$th!"northw nd.mdb""" dbconn.0pen!" sHl="S-(-73 U CR09 c#stomers" dbcomm=<ew 0le>b7omm$nd!sHl2dbconn" dbre$d=dbcomm.-4ec#teRe$der!" c#stomers.>$t$So#rce=dbre$d c#stomers.>$t$6 nd!" dbre$d.7lose!" dbconn.7lose!" end s#b </scr pt> <html> <body> <+orm r#n$t="ser%er"> <$sp,Repe$ter d="c#stomers" r#n$t="ser%er"> <He$der3empl$te> <t$ble border="*" w dth="*88%"> <tr> <th>7omp$nyn$me</th> <th>7ont$ctn$me</th> <th>/ddress</th> <th>7 ty</th> </tr> </He$der3empl$te> <:tem3empl$te> <tr> <td><%Q7ont$ ner.>$t$:tem!"comp$nyn$me""%></td> <td><%Q7ont$ ner.>$t$:tem!"cont$ctn$me""%></td> <td><%Q7ont$ ner.>$t$:tem!"$ddress""%></td> <td><%Q7ont$ ner.>$t$:tem!"c ty""%></td> </tr> </:tem3empl$te> <Cooter3empl$te> </t$ble> </Cooter3empl$te> </$sp,Repe$ter> </+orm> </body> </html>

%lose t'e &ata$ase %onnection


3lwa's close "oth the +ata?eader and data"ase connection after access to the data"ase is no longer re%uired*

dbre$d.7lose!" dbconn.7lose!"

;TM. Server %ontrols

;TM. server controls are ;TM. tags understood $y t'e server.

;TM. Server %ontrols


1TM/ elements in 3S2 .NET files are, "' default, treated as te#t. To ma,e these elements programma"le, add a runatJ"ser$er" attri"ute to the 1TM/ element. This attri"ute indicates that the element should "e treated as a ser$er control. Note@ 3ll 1TM/ ser$er controls must "e within a GformI tag with the runatJ"ser$er" attri"uteD Note@ 3S2 .NET re%uires that all 1TM/ elements must "e properl' closed and properl' nested. ;TM. Server %ontrol 1tml3nchor 1tmlButton 1tml5orm 1tmlGeneric 1tml mage 1tml nputButton 1tml nput6hec,Bo# 1tml nput5ile 1tml nput1idden 1tml nput mage 1tml nput?adioButton 1tml nputTe#t 1tmlSelect 1tmlTa"le 1tmlTa"le6ell 1tmlTa"le?ow 1tmlTe#t3rea &escri)tion 6ontrols an GaI 1TM/ element 6ontrols a G"uttonI 1TM/ element 6ontrols a GformI 1TM/ element 6ontrols other 1TM/ element not specified "' a specific 1TM/ ser$er control, li,e G"od'I, Gdi$I, GspanI, etc. 6ontrols an GimageI 1TM/ element 6ontrols Ginput t'peJ""utton"I, Ginput t'peJ"su"mit"I, and Ginput t'peJ"reset"I 1TM/ elements 6ontrols an Ginput t'peJ"chec,"o#"I 1TM/ element 6ontrols an Ginput t'peJ"file"I 1TM/ element 6ontrols an Ginput t'peJ"hidden"I 1TM/ element 6ontrols an Ginput t'peJ"image"I 1TM/ element 6ontrols an Ginput t'peJ"radio"I 1TM/ element 6ontrols Ginput t'peJ"te#t"I and Ginput t'peJ"password"I 1TM/ elements 6ontrols a GselectI 1TM/ element 6ontrols a Gta"leI 1TM/ element 6ontrols GtdIand GthI 1TM/ elements 6ontrols a GtrI 1TM/ element 6ontrols a Gte#tareaI 1TM/ element

We$ Server %ontrols

We$ server controls are s)ecial "S+ .NET tags understood $y t'e server.

We$ Server %ontrols


/i,e 1TM/ ser$er controls, We" ser$er controls are also created on the ser$er and the' re%uire a runatJ"ser$er" attri"ute to wor,. 1owe$er, We" ser$er controls do not necessaril' map to an' e#isting 1TM/ elements and the' ma' represent more comple# elements.

The s'nta# for creating a We" ser$er control is*

<$sp,control'n$me
We$ Server %ontrol 3d?otator Button 6alendar 6hec,Bo# 6hec,Bo#/ist +ataGrid +ata/ist +rop+own/ist 1'per/in, mage mageButton /a"el /in,Button /istBo# /iteral 2anel 2lace1older ?adioButton ?adioButton/ist ?epeater Ta"le Ta"le6ell Ta"le?ow Te#tBo# .ml

d="some' d" r#n$t="ser%er" />


&escri)tion +ispla's a se%uence of images +ispla's a push "utton +ispla's a calendar +ispla's a chec, "o# 6reates a multi!selection chec, "o# group +ispla's fields of a data source in a grid +ispla's items from a data source "' using templates 6reates a drop!down list 6reates a h'perlin, +ispla's an image +ispla's a clic,a"le image +ispla's static content which is programma"le :lets 'ou appl' st'les to its content; 6reates a h'perlin, "utton 6reates a single! or multi!selection drop!down list +ispla's static content which is programma"le :does not let 'ou appl' st'les to its content; 2ro$ides a container for other controls ?eser$es space for controls added "' code 6reates a radio "utton 6reates a group of radio "uttons +ispla's a repeated list of items "ound to the control 6reates a ta"le 6reates a ta"le cell 6reates a ta"le row 6reates a te#t "o# +ispla's an .M/ file or the results of an .S/ transform

,alidation Server %ontrols

,alidation server controls is used to validate user-in)ut.

,alidation Server %ontrols


3 9alidation ser$er control is used to $alidate the data of an input control. f the data does not pass $alidation, it will displa' an error message to the user.

The s'nta# for creating a 9alidation ser$er control is*

<$sp,control'n$me

d="some' d" r#n$t="ser%er" />


&escri)tion 6ompares the $alue of one input control to the $alue of another input control or to a fi#ed $alue 3llows 'ou to write a method to handle the $alidation of the $alue entered 6hec,s that the user enters a $alue that falls "etween two $alues Ensures that the $alue of an input control matches a specified pattern Ma,es an input control a re%uired field +ispla's a report of all $alidation errors occurred in a We" page

,alidation Server %ontrol 6ompare9alidator 6ustom9alidator ?ange9alidator ?egularE#pression9alidator ?e%uired5ield9alidator 9alidationSummar'

"S+ .NET Exa

)les

"S+. NET ;TM. %ontrols 1TM/3nchor 1TM/Button 1TM/ mage 1TM/ mage ( 1TM/ nput"utton 1TM/ nput6hec,"o# 1TM/ nput1idden 1TM/ nput mage 1TM/ nput?adio"utton 1TM/Ta"le 1TM/Ta"le ( 1TM/Te#tarea "S+. NET We$ %ontrols 3d?otator Button Button ( 6alendar 6alendar ( 6alendar B 6hec,"o# 6hec,"o#/ist +ata/ist +ata/ist with st'les +ata/ist with G3lternating temTemplateI +ropdown/ist 1'perlin, mage

mageButton /a"el /in,Button /ist"o# /iteral /iteral ( 2anel ?adio"utton ?adio"utton/ist ?epeater ?epeater with G3lternating temTemplateI ?epeater with GSeparatorTemplateI Ta"le Ta"le ( Te#t"o# Te#t"o# ( .M/ "S+. NET ,alidation %ontrols 6ompare9alidator 6ompare9alidator ( 6ustom9alidator ?ange9alidator ?ange9alidator ( ?egularE#pression9alidator ?e%uired5ield9alidator 9alidationsummar' 9alidationsummar' ( "S+. NET Events 2ageK/oad 2age. s2ostBac, "S+. NET &ata #inding 3rra'/ist ?adioButton/ist 3rra'/ist +rop+own/ist 1ashta"le ?adioButton/ist E 1ashta"le ?adio"utton/ist ( 1ashta"le +rop+own/ist Sorted/ist ?adioButton/ist E Sorted/ist ?adio"utton/ist ( Sorted/ist +rop+own/ist .M/ ?adio"utton/ist "S+. NET &ata$ase +ata"ase connection ! Bind to a ?epeater control +ata"ase connection ! Bind to a +ata/ist control

Potrebbero piacerti anche