+ All Categories
Home > Documents > ASP Dot Net Tutorial

ASP Dot Net Tutorial

Date post: 03-Jun-2018
Category:
Upload: rajeshd84
View: 231 times
Download: 0 times
Share this document with a friend

of 41

Transcript
  • 8/12/2019 ASP Dot Net Tutorial

    1/41

    ASP.NET Tutorial - with ASP.NET 2.0

    ASP.NET is the next generation ASP, but it's not an upgraded version of ASP. ASP.NET is an entirely newtechnology for serverside scripting.ASP.NET is a part of the !icrosoft .NET fra"ewor#, and a powerful tool for creating dyna"ic and interactiveweb pages.

    ASP.NET Introduction$hat %ou Should Already &nowefore you continue you should have a basic understanding of the following(

    $$$, )T!*, +!* and the basics of building $eb pages Scripting languages li#e avaScript or -Script The basics of server side scripting li#e ASP or P)P

    What is Classic ASP?!icrosoft's previous server side scripting technology ASP Active Server Pages/ is now often called classicASP.

    ASP 0.1 was the last version of classic ASP.

    ASP.NET is NOT ASP

    ASP.NET is the next generation ASP, but it's not an upgraded version of ASP. ASP.NET is an entirely new technology for serverside scripting. 2t was written fro" the ground up

    and is not bac#ward co"patible with classic ASP. ASP.NET is the "a3or part of the !icrosoft's .NET 4ra"ewor#.

    What is ASP.NET?

    ASP.NET is a server side scripting technology that enables scripts e"bedded in web pages/ to beexecuted by an 2nternet server.

    ASP.NET is a !icrosoft Technology ASP stands for Active Server Pages ASP.NET is a progra" that runs inside 22S 22S 2nternet 2nfor"ation Services/ is !icrosoft's 2nternet server 22S co"es as a free co"ponent with $indows servers 22S is also a part of $indows 5111 and +P Professional $hat is an ASP.NET 4ile6 An ASP.NET file is 3ust the sa"e as an )T!* file An ASP.NET file can contain )T!*, +!*, and scripts Scripts in an ASP.NET file are executed on the server An ASP.NET file has the file extension 7.aspx7 )ow 8oes ASP.NET $or#6 $hen a browser re9uests an )T!* file, the server returns the file $hen a browser re9uests an ASP.NET file, 22S passes the re9uest to the ASP.NET engine on the

    server The ASP.NET engine reads the file, line by line, and executes the scripts in the file

    4inally, the ASP.NET file is returned to the browser as plain )T!*

    What is ASP+?ASP: is the sa"e as ASP.NET.ASP: is 3ust an early na"e used by !icrosoft when they developed ASP.NET.

    The icroso!t .NET "ra#ewor$

    The .NET 4ra"ewor# is the infrastructure for the !icrosoft .NET platfor".

    1

  • 8/12/2019 ASP Dot Net Tutorial

    2/41

    The .NET 4ra"ewor# is an environ"ent for building, deploying, and running $eb applications and $ebServices.

    !icrosoft's first server technology ASP Active Server Pages/, was a powerful and flexible 7progra""inglanguage7. ut it was too code oriented. 2t was not an application fra"ewor# and not an enterprisedevelop"ent tool.

    The !icrosoft .NET 4ra"ewor# was developed to solve this proble".

    .NET "ra#ewor$s $e%words&

    Easier and 9uic#er progra""ing ;educed a"ount of code 8eclarative progra""ing "odel ;icher server control hierarchy with events *arger class library etter support for develop"ent tools

    The .NET "ra#ewor$ consists o! ' #ain (arts&Progra""ing languages(

  • 8/12/2019 ASP Dot Net Tutorial

    3/41

    +!*based co"ponents @ser authentication, with accounts and roles )igher scalability 2ncreased perfor"ance

  • 8/12/2019 ASP Dot Net Tutorial

    4/41

    ASP.NET InstallinASP.NET is easy to install. ust follow the instructions below.

    What ou Need

    A Windows Co#(uterASP.NET is a !icrosoft technology. To run ASP.NET you need a co"puter capable of running $indows.$indows 5111 or +P2f you are serious about developing ASP.NET applications you should install $indows 5111 Professional or$indows +P Professional.2n both cases, "a#e sure you install the 2nternet 2nfor"ation Services 22S/ fro" the Add>;e"ove $indowsco"ponents dialog.

    Ser)ice Pac$s and (datesefore ASP.NET can be installed on your co"puter, it is necessary to have all relevant service pac#s andsecurity updates installed.The easiest way to do this is to activate your $indows 2nternet @pdate. $hen you access the $indows@pdate page, you will be instructed to install the latest service pac#s and all critical security updates. 4or

    $indows 5111, "a#e sure you install Service Pac# 5. 2 will also reco""end that you install 2nternet ExplorerC.

    ,e#o)e our 1eta ersion2f you have a eta version of ASP.NET installed, we reco""end that you co"pletely uninstall it. Br evenbetter( start with a fresh $indows 5111 or +P installation.

    Install .NET4ro" your $indows @pdate you can now select to install the !icrosoft .NET 4ra"ewor#.After download, the .NET fra"ewor# will install itself on your co"puter there are no options to select forinstallation.%ou should now be ready to develop your first ASP.NET applicationD

    The .NET So!tware *e)elo(#ent 3it2f you have the necessary bandwidth to download over 01 !, you "ight consider downloading the full!icrosoft .NET Software 8evelop"ent &it S8&/.$e fully reco""end getting the S8& for learning "ore about .NET and for the docu"entation, sa"ples, andtools included.

    Connection S(eed and *ownload Ti#e2f you have a slow 2nternet connection, you "ight have proble"s downloading large files li#e the servicepac#s, the S8& and the latest version of 2nternet Explorer.2f download speed is a proble", our best suggestion is to get the latest files fro" so"eone else, fro" acolleague, fro" a friend, or fro" one of the

  • 8/12/2019 ASP Dot Net Tutorial

    5/41

    Fh5G)ello $0SchoolsDF>h5GF>centerGF>bodyGF>ht"lG

    2f you want to try it yourself, save the code in a file called 7firstpage.ht"7, and create a lin# to the file li#e this(firstpage.ht"

    )ello $0Schools in ASP.NETThe si"plest way to convert an )T!* page into an ASP.NET page is to copy the )T!* file to a new f ile withan .aspx extension.This code dis(la%s our e4a#(le as an ASP.NET (ae&Fht"lGFbody bgcolorH7yellow7GFcenterGFh5G)ello $0SchoolsDF>h5GF>centerGF>bodyGF>ht"lG

    2f you want to try it yourself, save the code in a file called 7firstpage.aspx7, and create a lin# to the file li#ethis(firstpage.aspx

    ow *oes it Wor$?4unda"entally an ASP.NET page is 3ust the sa"e as an )T!* page.An )T!* page has the extension .ht". 2f a browser re9uests an )T!* page fro" the server, the serversends the page to the browser without any "odifications.An ASP.NET page has the extension .aspx. 2f a browser re9uests an ASP.NET page, the server processesany executable code in the page, before the result is sent bac# to the browser.The ASP.NET page above does not contain any executable code, so nothing is executed. 2n the nextexa"ples we will add so"e executable code to the page to de"onstrate the difference between static )T!*pages and dyna"ic ASP pages.

    Classic ASPActive Server Pages ASP/ has been around for several years. $ith ASP, executable code can be placedinside )T!* pages.Previous versions of ASP before ASP .NET/ are often called

  • 8/12/2019 ASP Dot Net Tutorial

    6/41

    FcenterGFh5G)ello $0SchoolsDF>h5GFpGFI;esponse.$ritenow//IGF>pGF>centerGF>bodyGF>ht"lG2f you want to try it yourself, save the code in a file called 7dynpage.aspx7, and create a lin# to the file li#e

    this( dynpage.aspx

    ASP.NET )s Classic ASPThe previous exa"ples didn't de"onstrate any differences between ASP.NET and pGF>centerGF>bodyGF>ht"lG

    The code above illustrates a li"itation in

  • 8/12/2019 ASP Dot Net Tutorial

    7/41

    code for a given event/. The PageJ*oad event is one of "any events that ASP.NET understands(FscriptrunatH7server7GSub PageJ*oadlin#.);efH7http(>>www.w0schools.co"7End SubF>scriptG

    Fht"lGFbodyG

    Ffor" runatH7server7GFa idH7lin#7 runatH7server7G-isit $0SchoolsDF>aGF>for"G

    F>bodyGF>ht"lG

    The executable code itself has been "oved outside the )T!*.ASP.NET $eb Server G2n the following exa"ple we declare a utton server control in an .aspx file. Then we create an eventhandler for the scriptGFht"lGFbodyGFfor" runatH7server7G

    Fasp(utton idH7button7 TextH7GF>for"GF>bodyGF>ht"lG

    ASP.NET - alidation Ser)er Controls

    -alidation server controls are used to validate userinput. 2f the userinput does not pass validation, it willdisplay an error "essage to the user.Each validation control perfor"s a specific type of validation li#e validating against a specific value or arange of values/.y default, page validation is perfor"ed when a utton, 2"ageutton, or *in#utton control is clic#ed. %oucan prevent validation when a button control is clic#ed by setting the G2n the following exa"ple we declare one Textox control, one utton control, and one ;ange-alidatorcontrol in an .aspx file. 2f validation fails, the text 7The value "ust be fro" to 11D7 will be displayed in the

    ,anealidator control&E4a#(leFht"lGFbodyGFfor" runatH7server7GFpGEnter a nu"ber fro" to 11(

    7

  • 8/12/2019 ASP Dot Net Tutorial

    8/41

    Fasp(Textox idH7tbox7 runatH7server7 >GFbr >GFbr >GFasp(utton TextH7Sub"it7 runatH7server7 >GF>pGFpGFasp(;ange-alidatorGF>pGF>for"GF>bodyGF>ht"lG

    ASP.NET - E)entsAn Event )andler is a subroutine that executes code for a given event.

    ASP.NET - E)ent andlers*oo# at the following code(FIlbl.TextH7The date and ti"e is 7 K now/IGFht"lGFbodyGFfor" runatH7server7GFh0GFasp(label idH7lbl7 runatH7server7 >GF>h0GF>for"GF>bodyGF>ht"lG$hen will the code above be executed6 The answer is( 7%ou don't #now...7

    The Pae65oad E)ent

    The PageJ*oad event is one of "any events that ASP.NET understands. The PageJ*oad event is triggeredwhen a page loads, and ASP.NET will auto"atically call the subroutine PageJ*oad, and execute the codeinside it(Exa"pleFscript runatH7server7GSub PageJ*oadlbl.TextH7The date and ti"e is 7 K now/End SubF>scriptGFht"lGFbodyGFfor" runatH7server7GFh0GFasp(label idH7lbl7 runatH7server7 >GF>h0GF>for"GF>bodyGF>ht"lGNote: The $age%Loa event contains no ob&ect references or event arguments'

    The Pae.IsPost1ac$ Pro(ert%The PageJ*oad subroutine runs E-E;% ti"e the page is loaded. 2f you want to execute the code in thePageJ*oad subroutine only the 42;ST ti"e the page is loaded, you can use the Page.2sPostac# property.2f the Page.2sPostac# property is false, the page is loaded for the first ti"e, if it is true, the page is postedbac# to the server i.e. fro" a button clic# on a for"/(Exa"pleFscript runatH7server7GSub PageJ*oadif Not Page.2sPostac# then lbl.TextH7The date and ti"e is 7 K now/end ifEnd Sub

    8

  • 8/12/2019 ASP Dot Net Tutorial

    9/41

    Sub sub"its As Bb3ect, e As EventArgs/lbl5.TextH7)ello $orldD7End SubF>scriptGFht"lGFbodyGFfor" runatH7server7G

    Fh0GFasp(label idH7lbl7 runatH7server7 >GF>h0GFh0GFasp(label idH7lbl57 runatH7server7 >GF>h0GFasp(button textH7Sub"it7 onclic#H7sub"it7 runatH7server7 >GF>for"GF>bodyGF>ht"lGThe exa"ple above will write the 7The date and ti"e is....7 "essage only the first ti"e the page is loaded.$hen a user clic#s on the Sub"it button, the sub"it subroutine will write 7)ello $orldD7 to the second label,but the date and ti"e in the first label will not change.

    ASP.NET We/ "or#sAll server controls "ust appear within a Ffor"G tag, and the Ffor"G tag "ust contain the runatH7server7attribute.

    ASP.NET We/ "or#sAll server controls "ust appear within a Ffor"G tag, and the Ffor"G tag "ust contain the runatH7server7attribute. The runatH7server7 attribute indicates that the for" should be processed on the server. 2t alsoindicates that the enclosed controls can be accessed by server scripts(Ffor" runatH7server7G...)T!* : server controlsF>for"G

    Note: The form is alwa#s submitte to the !age itself. f #ou s!ecif# an action attribute( it is ignore. f #ouomit the metho attribute( it will be set to metho="!ost" b# efault. Also( if #ou o not s!ecif# the name ani attributes( the# are automaticall# assigne b# A)$.N*T.

    Note: An .as!+ !age can onl# contain ,N* control'

    2f you select view source in an .aspx page containing a for" with no na"e, "ethod, action, or id attributespecified, you will see that ASP.NET has added these attributes to the for". 2t loo#s so"ething li#ethis(Ffor" na"eH7Jctl17 "ethodH7post7 actionH7page.aspx7 idH7Jctl17G...so"e codeF>for"G

    Su/#ittin a "or#A for" is "ost often sub"itted by clic#ing on a button. The utton server control in ASP.NET has thefollowing for"at(Fasp(utton idH7id7 textH7label7 BnGThe id attribute defines a uni9ue na"e for the button and the text attribute assigns a label to the button. TheonscriptGFht"lGFbodyGFfor" runatH7server7GFasp(utton idH7button7 TextH7GF>for"GF>bodyG

    9

  • 8/12/2019 ASP Dot Net Tutorial

    10/41

    F>ht"lG

    ASP .NET aintainin the iewState

    %ou "ay save a lot of coding by "aintaining the -iewState of the ob3ects in your $eb 4or".

    aintainin the iewState$hen a for" is sub"itted in classic ASP, all for" values are cleared. Suppose you have sub"itted a for"with a lot of infor"ation and the server co"es bac# with an error. %ou will have to go bac# to the for" andcorrect the infor"ation. %ou clic# the bac# button, and what happens.......A** for" values are for"GFIdi" fna"efna"eH;e9uest.4or"7fna"e7/2f fna"eFG77 Then;esponse.$rite7)ello 7 K fna"e K 7D7/End 2fIGF>bodyGF>ht"lG

    )ere is the new ASP .NET way. $hen you clic# on the sub"it button, the for" value will NBTdisappear(Exa"ple

  • 8/12/2019 ASP Dot Net Tutorial

    11/41

    Ffor" runatH7server7G%our na"e( Fasp(Textox idH7txt7 runatH7server7 >GFasp(utton BnGFpGFasp(*abel idH7lbl7 runatH7server7 >GF>pGF>for"GF>bodyGF>ht"lG

    ASP .NET - The Te4t1o4 ControlThe Textox control is used to create a text box where the user can input text.

    The Te4t1o4 ControlThe Textox control is used to create a text box where the user can input text.The Textox control's attributes and properties are listed in our web controls reference page.The exa"ple below de"onstrates so"e of the attributes you "ay use with the Textox control(E4a#(leFht"lGFbodyGFfor" runatH7server7GA /asic Te4t1o4&Fasp(Textox idH7tb7 runatH7server7 >GFbr >GFbr >G

    A (assword Te4t1o4&Fasp(Textox idH7tb57 Text!odeH7password7 runatH7server7 >GFbr >GFbr >G

    A Te4t1o4 with te4t&Fasp(Textox idH7tb7 TextH7)ello $orldD7 runatH7server7 >GFbr >GFbr >G

    A #ultiline Te4t1o4&Fasp(Textox idH7tb07 Text!odeH7"ultiline7 runatH7server7 >G

    Fbr >GFbr >G

    A Te4t1o4 with heiht&Fasp(Textox idH7tbC7 rowsH7L7 Text!odeH7"ultiline7runatH7server7 >GFbr >GFbr >G

    A Te4t1o4 with width&Fasp(Textox idH7tbL7 colu"nsH7017 runatH7server7 >G

    F>for"GF>bodyGF>ht"lG

    Add a Scri(t

    The contents and settings of a Textox control "ay be changed by server scripts when a for" is sub"itted.A for" can be sub"itted by clic#ing on a button or when a user changes the value in the Textox control.2n the following exa"ple we declare one Textox control, one utton control, and one *abel control in an.aspx file. $hen the sub"it button is triggered, the sub"it subroutine is executed. The sub"it subroutinewrites a text to the *abel control(E4a#(leFscript runatH7server7GSub sub"itsender As Bb3ect, e As EventArgs/lbl.TextH7%our na"e is 7 K txt.TextEnd SubF>scriptG

    11

  • 8/12/2019 ASP Dot Net Tutorial

    12/41

    Fht"lGFbodyGFfor" runatH7server7GEnter your na"e(Fasp(Textox idH7txt7 runatH7server7 >GFasp(utton BnGFpGFasp(*abel idH7lbl7 runatH7server7 >GF>pG

    F>for"GF>bodyGF>ht"lG

    2n the following exa"ple we declare one Textox control and one *abel control in an .aspx f ile. $hen youchange the value in the Textox and either clic# outside the Textox or press the Tab #ey, the changesubroutine is executed. The sub"it subroutine writes a text to the *abel controlE4a#(leFscript runatH7server7GSub changesender As Bb3ect, e As EventArgs/lbl.TextH7%ou changed text to 7 K txt.TextEnd SubF>scriptGFht"lGFbodyG

    Ffor" runatH7server7GEnter your na"e(Fasp(Textox idH7txt7 runatH7server7textH7)ello $orldD7ontextchangedH7change7 autopostbac#H7true7>GFpGFasp(*abel idH7lbl7 runatH7server7 >GF>pGF>for"GF>bodyGF>ht"lG

    ASP.NET - The 1utton ControlThe utton control is used to display a push button.

    The 1utton ControlThe utton control is used to display a push button. The push button "ay be a sub"it button or a co""andbutton. y default, this control is a sub"it button.A sub"it button does not have a co""and na"e and it posts the page bac# to the server when it is clic#ed.2t is possible to write an event handler to control the actions perfor"ed when the sub"it button is clic#ed.A co""and button has a co""and na"e and allows you to create "ultiple utton controls on a page. 2t ispossible to write an event handler to control the actions perfor"ed when the co""and button is clic#ed.The utton control's attributes and properties are listed in our web controls reference page.The e4a#(le /elow de#onstrates a si#(le 1utton control&

    Fht"lGFbodyGFfor" runatH7server7G

    Fasp(utton idH7b7 TextH7Sub"it7 runatH7server7 >GF>for"GF>bodyGF>ht"lG

    Add a Scri(tA for" is "ost often sub"itted by clic#ing on a button.2n the following exa"ple we declare one Textox control, one utton control, and one *abel control in an.aspx file. $hen the sub"it button is triggered, the sub"it subroutine is executed. The sub"it subroutinewrites a text to the *abel control(E4a#(le

    12

  • 8/12/2019 ASP Dot Net Tutorial

    13/41

    Fscript runatH7server7GSub sub"itsender As Bb3ect, e As EventArgs/lbl.TextH7%our na"e is 7 K txt.TextEnd SubF>scriptGFht"lGFbodyG

    Ffor" runatH7server7GEnter your na"e(Fasp(Textox idH7txt7 runatH7server7 >GFasp(utton BnGFpGFasp(*abel idH7lbl7 runatH7server7 >GF>pGF>for"GF>bodyGF>ht"lG

    ASP.NET - *ata 1indin$e "ay use data binding to fill lists with selectable ite"s fro" an i"ported data source, li#e a database, an+!* file, or a script.

    *ata 1indinThe following controls are list controls which support data binding(

    asp(;adioutton*ist asp(GFasp(*ist2te" valueH747 textH74rance7 >GFasp(*ist2te" valueH727 textH72taly7 >GF>asp(;adioutton*istGF>for"GF>bodyGF>ht"lG

    )owever, with data binding we "ay use a separate source, li#e a database, an +!* file, or a script to fill thelist with selectable ite"s.y using an i"ported source, the data is separated fro" the )T!*, and any changes to the ite"s are "adein the separate data source.2n the next three chapters, we will describe how to bind data fro" a scripted data source.

    ASP.NET - The Arra%5ist O/8ectArray*ist 8rop8own*istArray*ist ;adioutton*ist

    Create an Arra%5istThe Array*ist ob3ect is a collection of ite"s containing a single data value.2te"s are added to the Array*ist with the Add/ "ethod.The following code creates a new Array*ist ob3ect na"ed "ycountries and four ite"s are added(Fscript runatH7server7GSub PageJ*oad

    13

  • 8/12/2019 ASP Dot Net Tutorial

    14/41

    if Not Page.2sPostac# then di" "ycountriesHNew Array*ist "ycountries.Add7Norway7/ "ycountries.Add7Sweden7/ "ycountries.Add74rance7/ "ycountries.Add72taly7/end if

    end subF>scriptG

    1% de!ault7 an Arra%5ist o/8ect contains 9: entries. An Arra%5ist can /e si;ed to its !inal si;e with theTri#ToSi;escriptG

    An Arra%5ist can also /e sorted al(ha/eticall% or nu#ericall% with the Sort

  • 8/12/2019 ASP Dot Net Tutorial

    15/41

    asp(*istbox

    To bind data to a ;adioutton*ist control, first create a ;adioutton*ist control without any asp(*ist2te"ele"ents/ in an .aspx page(Fht"lGFbodyGFfor" runatH7server7GFasp(;adioutton*ist idH7rb7 runatH7server7 >G

    F>for"GF>bodyGF>ht"lG

    Then add the script that builds the list and binds the values in the list to the ;adioutton*ist control(E4a#(leFscript runatH7server7GSub PageJ*oadif Not Page.2sPostac# then di" "ycountriesHNew Array*ist "ycountries.Add7Norway7/ "ycountries.Add7Sweden7/ "ycountries.Add74rance7/ "ycountries.Add72taly7/ "ycountries.Tri"ToSie/

    "ycountries.Sort/ rb.8ataSourceH"ycountries rb.8ataind/end ifend subF>scriptGFht"lGFbodyGFfor" runatH7server7GFasp(;adioutton*ist idH7rb7 runatH7server7 >GF>for"GF>bodyGF>ht"lG

    The 8ataSource property of the ;adioutton*ist control is set to the Array*ist and it defines the data sourceof the ;adioutton*ist control. The 8ataind/ "ethod of the ;adioutton*ist control binds the data sourcewith the ;adioutton*ist control.Note: The ata values are use as both the Te+t an -alue !ro!erties for the control. To a -alues that areifferent from the Te+t( use either the Hashtable ob&ect or the )orteList ob&ect.

    ASP.NET - The ashta/le O/8ectThe )ashtable ob3ect contains ite"s in #ey>value pairs.

    )ashtable ;adiobutton*ist )ashtable ;adiobutton*ist 5 )ashtable 8rop8own*ist

    Create a ashta/leThe )ashtable ob3ect contains ite"s in #ey>value pairs. The #eys are used as indexes, and very 9uic#searches can be "ade for values by searching through their #eys.2te"s are added to the )ashtable with the Add/ "ethod.The following code creates a )ashtable na"ed "ycountries and four ele"ents are added(FscriptrunatH7server7GSub PageJ*oadif Not Page.2sPostac# then di" "ycountriesHNew )ashtable "ycountries.Add7N7,7Norway7/

    15

  • 8/12/2019 ASP Dot Net Tutorial

    16/41

    "ycountries.Add7S7,7Sweden7/ "ycountries.Add747,74rance7/ "ycountries.Add727,72taly7/end ifend subF>scriptG

    *ata 1indinA )ashtable ob3ect "ay auto"atically generate the text and values to the following controls(

    asp(;adioutton*ist asp(for"GF>bodyGF>ht"lG

    Then add the scri(t that /uilds the list&Fscript runatH7server7Gsub PageJ*oadif Not Page.2sPostac# then di" "ycountriesHNew )ashtable "ycountries.Add7N7,7Norway7/ "ycountries.Add7S7,7Sweden7/ "ycountries.Add747,74rance7/ "ycountries.Add727,72taly7/ rb.8ataSourceH"ycountries rb.8ata-alue4ieldH7&ey7

    rb.8ataText4ieldH7-alue7 rb.8ataind/end ifend subF>scriptGFht"lGFbodyGFfor" runatH7server7GFasp(;adioutton*ist idH7rb7 runatH7server7 AutoPostac#H7True7 >GF>for"GF>bodyGF>ht"lG

    Then we add a sub routine to be executed when the user clic#s on an ite" in the ;adioutton*ist control.$hen a radio button is clic#ed, a text will appear in a label(E4a#(le

    Fscript runatH7server7Gsub PageJ*oadif Not Page.2sPostac# then di" "ycountriesHNew )ashtable "ycountries.Add7N7,7Norway7/ "ycountries.Add7S7,7Sweden7/ "ycountries.Add747,74rance7/ "ycountries.Add727,72taly7/ rb.8ataSourceH"ycountries rb.8ata-alue4ieldH7&ey7 rb.8ataText4ieldH7-alue7

    16

  • 8/12/2019 ASP Dot Net Tutorial

    17/41

    rb.8ataind/end ifend subsub display!essages as Bb3ect,e As EventArgs/lbl.textH7%our favorite country is( 7 K rb.Selected2te".Textend subF>scriptG

    Fht"lGFbodyGFfor" runatH7server7GFasp(;adioutton*ist idH7rb7 runatH7server7AutoPostac#H7True7 onSelected2ndexGFpGFasp(label idH7lbl7 runatH7server7 >GF>pGF>for"GF>bodyGF>ht"lG

    Note: ou cannot choose the sort orer of the items ae to the Hashtable. To sort items al!habeticall# ornumericall#( use the )orteList ob&ect.

    ASP.NET - The Sorted5ist O/8ectThe Sorted*ist ob3ect co"bines the features of both the Array*ist ob3ect and the )ashtable ob3ect.

    Sorted*ist ;adiobutton*ist Sorted*ist ;adiobutton*ist 5 Sorted*ist 8rop8own*ist

    The Sorted5ist O/8ectThe Sorted*ist ob3ect contains ite"s in #ey>value pairs. A Sorted*ist ob3ect auto"atically sort the ite"s inalphabetic or nu"eric order.

    2te"s are added to the Sorted*ist with the Add/ "ethod. A Sorted*ist can be sied to its final sie with theTri"ToSie/ "ethod.The !ollowin code creates a Sorted5ist na#ed #%countries and !our ele#ents are added&Fscript runatH7server7G

    sub PageJ*oadif Not Page.2sPostac# then di" "ycountriesHNew Sorted*ist "ycountries.Add7N7,7Norway7/ "ycountries.Add7S7,7Sweden7/ "ycountries.Add747,74rance7/ "ycountries.Add727,72taly7/end ifend subF>scriptG

    *ata 1indinA Sorted*ist ob3ect "ay auto"atically generate the text and values to the following controls(

    asp(;adioutton*ist asp(GF>for"G

    17

  • 8/12/2019 ASP Dot Net Tutorial

    18/41

    F>bodyGF>ht"lG

    Then add the scri(t that /uilds the list&Fscript runatH7server7Gsub PageJ*oad

    if Not Page.2sPostac# then di" "ycountriesHNew Sorted*ist "ycountries.Add7N7,7Norway7/ "ycountries.Add7S7,7Sweden7/ "ycountries.Add747,74rance7/ "ycountries.Add727,72taly7/ rb.8ataSourceH"ycountries rb.8ata-alue4ieldH7&ey7 rb.8ataText4ieldH7-alue7 rb.8ataind/end ifend subF>scriptGFht"lGFbodyG

    Ffor" runatH7server7GFasp(;adioutton*ist idH7rb7 runatH7server7 AutoPostac#H7True7 >GF>for"G

    F>bodyGF>ht"lG

    Then we add a sub routine to be executed when the user clic#s on an ite" in the ;adioutton*ist control.$hen a radio button is clic#ed, a text will appear in a label(E4a#(leFscript runatH7server7Gsub PageJ*oadif Not Page.2sPostac# then di" "ycountriesHNew Sorted*ist "ycountries.Add7N7,7Norway7/

    "ycountries.Add7S7,7Sweden7/ "ycountries.Add747,74rance7/ "ycountries.Add727,72taly7/ rb.8ataSourceH"ycountries rb.8ata-alue4ieldH7&ey7 rb.8ataText4ieldH7-alue7 rb.8ataind/end ifend subsub display!essages as Bb3ect,e As EventArgs/lbl.textH7%our favorite country is( 7 K rb.Selected2te".Textend subF>scriptGFht"lGFbodyGFfor" runatH7server7GFasp(;adioutton*ist idH7rb7 runatH7server7AutoPostac#H7True7 onSelected2ndexGFpGFasp(label idH7lbl7 runatH7server7 >GF>pGF>for"GF>bodyGF>ht"lG

    18

  • 8/12/2019 ASP Dot Net Tutorial

    19/41

    ASP .NET - >5 "iles$e can bind an +!* file to a list control.

    An >5 "ileere is an >5 !ile na#ed countries.4#l&F6x"l versionH7.17 encodingH72SBLO76GFcountriesG

    FcountryG FtextGNorwayF>textG FvalueGNF>valueGF>countryGFcountryG FtextGSwedenF>textG FvalueGSF>valueGF>countryGFcountryG FtextG4ranceF>textG FvalueG4F>valueGF>countryGFcountryG FtextG2talyF>textG FvalueG2F>valueG

    F>countryGF>countriesG

    1ind a *ataSet to a 5ist Control4irst, i"port the 7Syste".8ata7 na"espace. $e need this na"espace to wor# with 8ataSet ob3ects. 2ncludethe following directive at the top of an .aspx page(FIR 2"port Na"espaceH7Syste".8ata7 IGNext, create a 8ataSet for the +!* file and load the +!* file into the 8ataSet when the page is firstloaded(Fscript runatH7server7Gsub PageJ*oadif Not Page.2sPostac# then di" "ycountriesHNew 8ataSet "ycountries.;ead+"l!apPath7countries.x"l7//end ifend sub

    To /ind the *ataSet to a ,adio1utton5ist control7 !irst create a ,adio1utton5ist control GF>for"GF>bodyGF>ht"lG

    Then add the scri(t that /uilds the >5 *ataSet&FIR 2"port Na"espaceH7Syste".8ata7 IGFscript runatH7server7Gsub PageJ*oadif Not Page.2sPostac# then

    di" "ycountriesHNew 8ataSet "ycountries.;ead+"l!apPath7countries.x"l7// rb.8ataSourceH"ycountries rb.8ata-alue4ieldH7value7 rb.8ataText4ieldH7text7 rb.8ataind/end ifend subF>scriptGFht"lGFbodyG

    19

  • 8/12/2019 ASP Dot Net Tutorial

    20/41

    Ffor" runatH7server7GFasp(;adioutton*ist idH7rb7 runatH7server7AutoPostac#H7True7 onSelected2ndexGF>for"GF>bodyGF>ht"lG

    Then we add a sub routine to be executed when the user clic#s on an ite" in the ;adioutton*ist control.$hen a radio button is clic#ed, a text will appear in a label(E4a#(leFIR 2"port Na"espaceH7Syste".8ata7 IGFscript runatH7server7Gsub PageJ*oadif Not Page.2sPostac# then di" "ycountriesHNew 8ataSet "ycountries.;ead+"l!apPath7countries.x"l7// rb.8ataSourceH"ycountries rb.8ata-alue4ieldH7value7 rb.8ataText4ieldH7text7 rb.8ataind/end ifend sub

    sub display!essages as Bb3ect,e As EventArgs/lbl.textH7%our favorite country is( 7 K rb.Selected2te".Textend subF>scriptGFht"lGFbodyGFfor" runatH7server7GFasp(;adioutton*ist idH7rb7 runatH7server7AutoPostac#H7True7 onSelected2ndexGFpGFasp(label idH7lbl7 runatH7server7 >GF>pGF>for"GF>bodyGF>ht"lG

    ASP.NET - The ,e(eater ControlThe ;epeater control is used to display a repeated list of ite"s that are bound to the control.

    1ind a *ataSet to a ,e(eater ControlThe ;epeater control is used to display a repeated list of ite"s that are bound to the control. The ;epeatercontrol "ay be bound to a database table, an +!* file, or another list of ite"s. )ere we will show how tobind an +!* file to a ;epeater control.$e will use the following +!* file in our exa"ples 7cdcatalog.x"l7/(F6x"l versionH7.17 encodingH72SBLO76GFcatalogGFcdG

    FtitleGE"pire urles9ueF>titleG FartistGob 8ylanF>artistG FcountryG@SAF>countryG Fco"panyGpriceG FyearGOLF>yearGF>cdGFcdG FtitleG)ide your heartF>titleG FartistGonnie TylerF>artistG FcountryG@&F>countryG

    20

  • 8/12/2019 ASP Dot Net Tutorial

    21/41

    Fco"panyGco"panyG FpriceGO.O1F>priceG FyearGOF>yearGF>cdGFcdG FtitleGreatest )itsF>titleG FartistG8olly PartonF>artistG

    FcountryG@SAF>countryG Fco"panyG;co"panyG FpriceGO.O1F>priceG FyearGO5F>yearGF>cdGFcdG FtitleGStill got the bluesF>titleG FartistGary !ooreF>artistG FcountryG@&F>countryGFco"panyG-irgin recordsF>co"panyG FpriceG1.51F>priceG FyearGOO1F>yearGF>cdGFcdG FtitleGErosF>titleG

    FartistGEros ;a"aottiF>artistG FcountryGE@F>countryG Fco"panyG!F>co"panyG FpriceGO.O1F>priceG FyearGOOF>yearGF>cdGF>catalogG

    4irst, i"port the 7Syste".8ata7 na"espace. $e need this na"espace to wor# with 8ataSet ob3ects. 2ncludethe following directive at the top of an .aspx page(FIR 2"port Na"espaceH7Syste".8ata7 IGNext, create a 8ataSet for the +!* file and load the +!* file into the 8ataSet when the page is first loaded(Fscript runatH7server7Gsub PageJ*oadif Not Page.2sPostac# then di" "ycdcatalogHNew 8ataSet

    "ycdcatalog.;ead+"l!apPath7cdcatalog.x"l7//end ifend subThen we create a ;epeater control in an .aspx page. The contents of the F)eaderTe"plateG ele"ent arerendered first and only once within the output, then the contents of the F2te"Te"plateG ele"ent arerepeated for each 7record7 in the 8ataSet, and last, the contents of the F4ooterTe"plateG ele"ent arerendered once within the output(Fht"lGFbodyGFfor" runatH7server7GFasp(;epeater idH7cdcatalog7 runatH7server7GF)eaderTe"plateG...F>)eaderTe"plateGF2te"Te"plateG...F>2te"Te"plateGF4ooterTe"plateG...F>4ooterTe"plateGF>asp(;epeaterGF>for"GF>bodyGF>ht"lG

    21

  • 8/12/2019 ASP Dot Net Tutorial

    22/41

    Then we add the script that creates the 8ataSet and binds the "ycdcatalog 8ataSet to the ;epeater control.$e also fill the ;epeater control with )T!* tags and bind the data ite"s to the cells in theF2te"Te"plateGsection with the FI=scriptGFht"lGFbodyGFfor" runatH7server7GFasp(;epeater idH7cdcatalog7 runatH7server7GF)eaderTe"plateGFtable borderH77 widthH711I7GFtrG

    FthGTitleF>thGFthGArtistF>thGFthGthGFthGtdGFtdGFI=tdGFtdGFI=tableGF>4ooterTe"plateG

    F>asp(;epeaterGF>for"G

    F>bodyGF>ht"lG

    sin the @AlternatinIte#Te#(late

    %ou can add an FAlternating2te"Te"plateG ele"ent af ter the F2te"Te"plateG ele"ent to describe theappearance of alternating rows of output. 2n the following exa"ple each other row in the table will bedisplayed in a light grey color(Exa"pleFIR 2"port Na"espaceH7Syste".8ata7 IG

    Fscript runatH7server7G

    22

  • 8/12/2019 ASP Dot Net Tutorial

    23/41

    sub PageJ*oadif Not Page.2sPostac# then di" "ycdcatalogHNew 8ataSet "ycdcatalog.;ead+"l!apPath7cdcatalog.x"l7// cdcatalog.8ataSourceH"ycdcatalog cdcatalog.8ataind/end if

    end subF>scriptG

    Fht"lGFbodyG

    Ffor" runatH7server7GFasp(;epeater idH7cdcatalog7 runatH7server7G

    @eaderTe#(lateFtable borderH77 widthH711I7GFtrGFthGTitleF>thGFthGArtistF>thGFthGthG

    FthGtdGFtdGFI=tdGFtdGFI=tdGFtdGFI=tdGFtdGFI=tdGFtdGFI=tdGF>trGF>Alternating2te"Te"plateGF4ooterTe"plateGF>tableGF>4ooterTe"plateGF>asp(;epeaterGF>for"GF>bodyGF>ht"lG

    sin the @Se(aratorTe#(lateThe FSeparatorTe"plateG ele"ent can be used to describe a separator between each record. The followingexa"ple inserts a horiontal line between each table row(E4a#(leFIR 2"port Na"espaceH7Syste".8ata7 IGFscript runatH7server7G

    23

  • 8/12/2019 ASP Dot Net Tutorial

    24/41

    sub PageJ*oadif Not Page.2sPostac# then di" "ycdcatalogHNew 8ataSet "ycdcatalog.;ead+"l!apPath7cdcatalog.x"l7// cdcatalog.8ataSourceH"ycdcatalog cdcatalog.8ataind/end if

    end subF>scriptGFht"lGFbodyGFfor" runatH7server7GFasp(;epeater idH7cdcatalog7 runatH7server7GF)eaderTe"plateGFtable borderH717 widthH711I7GFtrGFthGTitleF>thGFthGArtistF>thGFthGthGFthGtdGFtdGFI=tdGFtdGFI=GF>tdG

    F>trGF>SeparatorTe"plateGF4ooterTe"plateGF>tableGF>4ooterTe"plateGF>asp(;epeaterGF>for"GF>bodyGF>ht"lG

    ASP.NET - The *ata5ist Control

    The 8ata*ist control is, li#e the ;epeater control, used to display a repeated list of ite"s that are bound tothe control. )owever, the 8ata*ist control adds a table around the data ite"s by default.

    1ind a *ataSet to a *ata5ist ControlThe 8ata*ist control is, li#e the ;epeater control, used to display a repeated list of ite"s that are bound tothe control. )owever, the 8ata*ist control adds a table around the data ite"s by default. The 8ata*istcontrol "ay be bound to a database table, an +!* file, or another list of ite"s. )ere we will show how tobind an +!* file to a 8ata*ist control.$e will use the following +!* file in our exa"ples 7cdcatalog.x"l7/(F6x"l versionH7.17 encodingH72SBLO76GFcatalogG

    24

  • 8/12/2019 ASP Dot Net Tutorial

    25/41

    FcdG FtitleGE"pire urles9ueF>titleG FartistGob 8ylanF>artistG FcountryG@SAF>countryG Fco"panyGpriceG FyearGOLF>yearG

    F>cdGFcdG FtitleG)ide your heartF>titleG FartistGonnie TylerF>artistG FcountryG@&F>countryG Fco"panyGco"panyG FpriceGO.O1F>priceG FyearGOF>yearGF>cdGFcdG FtitleGreatest )itsF>titleG FartistG8olly PartonF>artistG FcountryG@SAF>countryG Fco"panyG;co"panyG FpriceGO.O1F>priceG

    FyearGO5F>yearGF>cdGFcdG FtitleGStill got the bluesF>titleG FartistGary !ooreF>artistG FcountryG@&F>countryGFco"panyG-irgin recordsF>co"panyG FpriceG1.51F>priceG FyearGOO1F>yearGF>cdGFcdG FtitleGErosF>titleG FartistGEros ;a"aottiF>artistG FcountryGE@F>countryG Fco"panyG!F>co"panyG

    FpriceGO.O1F>priceG FyearGOOF>yearGF>cdGF>catalogG

    "irst7 i#(ort the S%ste#.*ata na#es(ace. We need this na#es(ace to wor$ with *ataSet o/8ects.Include the !ollowin directi)e at the to( o! an .as(4 (ae&FIR 2"port Na"espaceH7Syste".8ata7 IGNext, create a 8ataSet for the +!* file and load the +!* file into the 8ataSet when the page is firstloaded(Fscript runatH7server7Gsub PageJ*oadif Not Page.2sPostac# then di" "ycdcatalogHNew 8ataSet "ycdcatalog.;ead+"l!apPath7cdcatalog.x"l7//end ifend subThen we create a 8ata*ist in an .aspx page. The contents of the F)eaderTe"plateG ele"ent are renderedfirst and only once within the output, then the contents of the F2te"Te"plateG ele"ent are repeated for each7record7 in the 8ataSet, and last, the contents of the F4ooterTe"plateG ele"ent are rendered once withinthe output(Fht"lGFbodyGFfor" runatH7server7GFasp(8ata*ist idH7cdcatalog7 runatH7server7GF)eaderTe"plateG

    25

  • 8/12/2019 ASP Dot Net Tutorial

    26/41

    ...F>)eaderTe"plateGF2te"Te"plateG...F>2te"Te"plateGF4ooterTe"plateG...

    F>4ooterTe"plateGF>asp(8ata*istGF>for"GF>bodyGF>ht"lG

    Then we add the script that creates the 8ataSet and binds the "ycdcatalog 8ataSet to the 8ata*ist control.$e also fill the 8ata*ist control with a F)eaderTe"plateG that contains the header of the table, anF2te"Te"plateG that contains the data ite"s to display, and a F4ooterTe"plateG that contains a text. Notethat the gridlines attribute of the 8ata*ist is set to 7both7 to display table borders(E4a#(leFIR 2"port Na"espaceH7Syste".8ata7 IGFscript runatH7server7Gsub PageJ*oadif Not Page.2sPostac# then

    di" "ycdcatalogHNew 8ataSet "ycdcatalog.;ead+"l!apPath7cdcatalog.x"l7// cdcatalog.8ataSourceH"ycdcatalog cdcatalog.8ataind/end ifend subF>scriptG

    Fht"lGFbodyGFfor" runatH7server7GFasp(8ata*ist idH7cdcatalog7gridlinesH7both7 runatH7server7GF)eaderTe"plateG!y asp(8ata*istGF>for"G

    F>bodyGF>ht"lG

    sin St%les%ou can also add styles to the 8ata*ist control to "a#e the output "ore fancy(E4a#(leFIR 2"port Na"espaceH7Syste".8ata7 IGFscript runatH7server7G

    26

  • 8/12/2019 ASP Dot Net Tutorial

    27/41

    sub PageJ*oadif Not Page.2sPostac# then di" "ycdcatalogHNew 8ataSet "ycdcatalog.;ead+"l!apPath7cdcatalog.x"l7// cdcatalog.8ataSourceH"ycdcatalog cdcatalog.8ataind/end if

    end subF>scriptG

    Fht"lGFbodyGFfor" runatH7server7GFasp(8ata*ist idH7cdcatalog7runatH7server7cellpaddingH757cellspacingH757borderstyleH7inset7bac#colorH7=eee7widthH711I7headerstylefontna"eH7-erdana7headerstylefontsieH75pt7

    headerstylehoriontalalignH7center7headerstylefontboldH7true7ite"stylebac#colorH7=OO7ite"styleforecolorH7=ffffff7footerstylefontsieH7Opt7footerstylefontitalicH7true7GF)eaderTe"plateG!y asp(8ata*istGF>for"GF>bodyGF>ht"lG

    sin the @AlternatinIte#Te#(late%ou can add an FAlternating2te"Te"plateG ele"ent af ter the F2te"Te"plateG ele"ent to describe theappearance of alternating rows of output. %ou "ay style the data in the FAlternating2te"Te"plateG sectionwithin the 8ata*ist control(E4a#(leFIR 2"port Na"espaceH7Syste".8ata7 IG

    Fscript runatH7server7Gsub PageJ*oadif Not Page.2sPostac# thendi" "ycdcatalogHNew 8ataSet"ycdcatalog.;ead+"l!apPath7cdcatalog.x"l7//cdcatalog.8ataSourceH"ycdcatalogcdcatalog.8ataind/end ifend subF>scriptGFht"lG

    27

  • 8/12/2019 ASP Dot Net Tutorial

    28/41

    FbodyGFfor" runatH7server7GFasp(8ata*ist idH7cdcatalog7runatH7server7cellpaddingH757cellspacingH757borderstyleH7inset7

    bac#colorH7=eee7widthH711I7headerstylefontna"eH7-erdana7headerstylefontsieH75pt7headerstylehoriontalalignH7center7headerstylefontboldH7True7ite"stylebac#colorH7=OO7ite"styleforecolorH7=ffffff7alternatingite"stylebac#colorH7=eee7alternatingite"styleforecolorH7=1111117footerstylefontsieH7Opt7footerstylefontitalicH7True7GF)eaderTe"plateG!y bodyGF>ht"lG

    ASP.NET - *ata/ase ConnectionA8B.NET is also a part of the .NET 4ra"ewor#. A8B.NET is used to handle data access. $ith A8B.NETyou can wor# with databases.

    E4a#(les&

    B*ata/ase connection - 1ind to a *ata5ist controlFIR 2"port Na"espaceH7Syste".8ata.Ble8b7 IGFscript runatH7server7Gsub PageJ*oaddi" dbconn,s9l,dbco"",dbreaddbconnHNew Ble8b

  • 8/12/2019 ASP Dot Net Tutorial

    29/41

    custo"ers.8ataind/dbread.)eaderTe"plateG

    F2te"Te"plateGFI=4ooterTe"plateG

    F>asp(8ata*istGF>for"GF>bodyGF>ht"lG

    ,esult&

    Custo#ers Ta/le

    Alfreds 4utter#iste in Bbere Str. L, erlinerglunds snabb#Wp in erguvsvXgen , *uleY

  • 8/12/2019 ASP Dot Net Tutorial

    30/41

    The ig db>northwind."db7//dbconn.Bpen/s9lH7SE*EthGFthGAddressF>thGFthGthGF>trGF>)eaderTe"plateG

    F2te"Te"plateGFtr bgcolorH7=f1f1f17GFtdGFI=tdGFtdGFI=tableGF>4ooterTe"plateG

    F>asp(;epeaterGF>for"G

    F>bodyGF>ht"lG

    ,esult&

    30

  • 8/12/2019 ASP Dot Net Tutorial

    31/41

    Co#(an%na#e Contactna#e Address Cit%

    Alfreds 4utter#iste !aria Anders Bbere Str. L erlinerglunds snabb#Wp

  • 8/12/2019 ASP Dot Net Tutorial

    32/41

    Fscript runatH7server7Gsub PageJ*oaddi" dbconn,s9l,dbco""dbconnHNew Ble8b

  • 8/12/2019 ASP Dot Net Tutorial

    33/41

    F>)eaderTe"plateGF2te"Te"plateGFtrGFtdGFI=tdGFtdGFI=tableGF>4ooterTe"plateGF>asp(;epeaterGF>for"GF>bodyGF>ht"lG

    Close the *ata/ase ConnectionAlways close both the 8ata;eader and database connection after access to the database is no longerre9uired(dbread.

  • 8/12/2019 ASP Dot Net Tutorial

    34/41

    The"es is another feature of ASP.NET 5.1. The"es, or s#ins, allow developers to create a custo"ied loo#for web applications.

    8esign goals for ASP.NET 5.1 the"es(!a#e it si"ple to custo"ie the appearance of a siteAllow the"es to be applied to controls, pages, and entire sites

    Allow all visual ele"ents to be custo"iedWe/ PartsASP.NET 5.1 $eb Parts can provide a consistent loo# for a site, while still allowing user custo"iation ofstyle and content.

    New controls(Mone controls areas on a page where the content is consistent$eb part controls content areas for each oneNavigation

    ASP.NET 5.1 has builtin navigation controls li#e Site !aps 8yna"ic )T!* "enus Tree -iews

    Securit%Security is very i"portant for protecting confidential and personal infor"ation.

    In ASP.NET 2.0 the !ollowin controls has /een added&

    A *ogin control, which provides login functionality A *oginStatus control, to control the login status A *oginNa"e control to display the current user na"e A *ogin-iew control, to provide different views depending on login status A

  • 8/12/2019 ASP Dot Net Tutorial

    35/41

    These controls are i"portant for better i"age display on "obile devices, li#e handheld co"puters and cellphones.

    Auto#atic Co#(ilation

    ASP.NET 5.1 provides auto"atic co"pilation. All files within a directory will be co"piled on the firstrun, including support for $S8*, and +S8 files.

  • 8/12/2019 ASP Dot Net Tutorial

    36/41

    The idH7aspnet>w0ho"e.aspx7G Fsite!apNode titleH7Services7 urlH7>aspnet>w0services.aspx7G Fsite!apNode titleH7Training7 urlH7>aspnet>w0training.aspx7>G Fsite!apNode titleH7Support7 urlH7>aspnet>w0support.aspx7>G F>site!apNodeG F>site!apNodeG

    36

  • 8/12/2019 ASP Dot Net Tutorial

    37/41

    F>site!apG

    ,ules !or creatin a site#a( !ile&The +!* file "ust contain a Fsite!apG tag surrounding the contentThe Fsite!apG tag can only have one Fsite!apNodeG child node the 7ho"e7 page/Each Fsite!apNodeG can have several child nodes web pages/Each Fsite!apNodeG has attributes defining page title and @;*

    Note( The site"ap file "ust be placed in the root directory of the web and the @;* attributes "ust berelative to the root directory.*%na#ic enuThe Fasp(!enuG control displays a standard site navigation "enu.

    Code E4a#(le&Fasp(Site!ap8ataSource idH7nav7 runatH7server7 >GFfor" runatH7server7GFasp(!enu runatH7server7 8ataSource2dH7nav7 >GF>for"GThe Fasp(!enuG control in the exa"ple above is a placeholder for a server created navigation "enu.The data source of the control is defined by the 8ataSource2d attribute. The idH7nav7 connects it to theFasp(Site!ap8ataSourceG control.The Fasp(Site!ap8ataSourceG control auto"atically connects to the default site"ap file web.site"ap/.

    TreeiewThe Fasp(Tree-iewG control displays a "ulti level navigation "enu.The "enu loo#s li#e a tree with branches that can be opened or closed with : or sy"bol.

    Code E4a#(le&Fasp(Site!ap8ataSource idH7nav7 runatH7server7 >GFfor" runatH7server7GFasp(Tree-iew runatH7server7 8ataSource2dH7nav7 >GF>for"G

    The Fasp(Tree-iewG control in the exa"ple above is a placeholder for a server created navigation "enu.The data source of the control is defined by the 8ataSource2d attribute. The idH7nav7 connects it to theFasp(Site!ap8ataSourceG control.The Fasp(Site!ap8ataSourceG control auto"atically connects to the default site"ap file web.site"ap/.

    Sitea(PathThe Site!apPath control displays the trail navigation path/ to the current page. The path acts as clic#ablelin#s to previous pages.@nli#e the Tree-iew and !enu control the Site!apPath control does NBT use a Site!ap8ataSource. TheSite!apPath control uses the web.site"ap file by default.Ti!s: f the )iteMa!$ath is!la#s incorrectl#( most li1el# there is an 23L error 4t#!o5 in the web.sitema! file.GF>for"GThe Fasp(Site!apPathG control in the exa"ple above is a placeholder for a server created site path display.

    T5 Ser)er Controls)T!* server controls are )T!* tags understood by the server.

    T5 Ser)er Controls)T!* ele"ents in ASP.NET files are, by default, treated as text. To "a#e these ele"ents progra""able,add a runatH7server7 attribute to the )T!* ele"ent. This attribute indicates that the ele"ent should betreated as a server control.Note: All HTML server controls must be within a tag with the runat="server" attribute'Note: A)$.N*T re6uires that all HTML elements must be !ro!erl# close an !ro!erl# neste.

    T5 Ser)er Control *escri(tion

    37

  • 8/12/2019 ASP Dot Net Tutorial

    38/41

    )t"lAnchor G

    We/ Ser)er Control *escri(tion

    Ad;otator 8isplays a se9uence of i"agesutton 8isplays a push button

  • 8/12/2019 ASP Dot Net Tutorial

    39/41

    Table

  • 8/12/2019 ASP Dot Net Tutorial

    40/41

    8ata*ist with styles 8ata*ist with FAlternating2te"Te"plateG 8ropdown*ist )yperlin# 2"age 2"ageutton

    *abel *in#utton *istbox *iteral *iteral 5 Panel ;adiobutton ;adiobutton*ist ;epeater ;epeater with FAlternating2te"Te"plateG ;epeater with FSeparatorTe"plateG Table Table 5

    Textbox Textbox 5 Textbox 0 +!*

    ASP.NET alidation Controls

  • 8/12/2019 ASP Dot Net Tutorial

    41/41


Recommended