Johdanto
WebFormsisoneofthreeprogrammingmodelsforcreatingASP.NETwebsitesandWebapplications.
TheothertwoprogrammingmodesareWebPagesandMVC(ModelViewController).
WebFormsisvanhinASP.NET-ohjelmointimalli.Itisanevent-drivenwebpage, joka integroi HTML:n, palvelinohjaimet ja palvelinkoodin.
WebFormsiscompiledandexecutedontheserver,andthentheservergeneratesHTMLanddisplaysitasawebpage.
WebFormshashundredsofWebcontrolsandWebcomponentsusedtocreateuser-drivenwebsiteswithdataaccess.
ominaisuudet
BasedonMicrosoftASP.NETtechnology.Inthistechnology,thecoderunningontheserverdynamicallygeneratesWebpageoutputtothebrowserorclientdevice.FormoreinformationaboutASP.NET,pleaserefertoASP.NETTechnicalBackgroundJohdanto.
Compatiblewithallbrowsersormobiledevices.TheWebFormspageautomaticallyrendersthecorrectHTMLthatconformstothebrowserforthestyle,layout,andotherfunctions.Inaddition,youcanalsochoosetodesigntheWebFormspagetorunonaspecificbrowser(suchasMicrosoftInternetExplorer5)andtakeadvantageofthefeaturesofthemulti-stylebrowserclient.
Compatiblewithanylanguagesupportedbythe.NETcommonlanguageruntime,includingMicrosoftVisualBasic,MicrosoftVisualC#andMicrosoftJScript.NET.
BasedonMicrosoft.NETFramework.Itprovidesalltheadvantagesoftheframework,includinghostingenvironment,typesafetyandinheritance.
InVisualStudio,itissupportedbypowerfulrapidapplicationdevelopment(RAD)tools,whichareusedtodesignandprogramforms.
ItcanbeextendedwithcontrolsthatprovideRADfunctionsforWebdevelopment,allowingyoutoquicklycreatemulti-styleuserinterfaces.
Beflexiblebecauseyoucanadduser-createdcontrolsandthird-partycontrolstothem.
Komponentit
IntheWebformpage,userinterfaceprogrammingisdividedintotwodifferentparts:visualcomponentsandlogic.IfyouhaveusedtoolslikeVisualBasicandVisualC++before,youwillagreethatthereissuchadivisionbetweenthevisualpartoftheformandthecodethatinteractswithitbehindtheform.
ThevisualelementiscalledtheWebform"page"(page).ThistypeofpageconsistsofafilecontainingstaticHTMLand/orASP.NETservercontrols.
Webformpagesareusedascontainersforstatictextandcontrolstobedisplayed.UsingtheVisualStudioWebFormDesignerandASP.NETservercontrols,youcandesigntheformthewayyouwouldinanyVisualStudioapplication.Formoreinformation,seeControlsavailableonWebFormspages.
Web-lomakkeenlogiikkasivu koostuu koodista, jonka luot vuorovaikutuksessa lomakkeen kanssa. Ohjelmointilogiikka sijoitetaan eri tiedostoon käyttäjäliittymätiedostosta. Tätä tiedostoa kutsutaan "takaa"tiedostoksi ja sillä on"aspx.vb"-tai "aspx.cs"-laajennus.
Tiedostorakenne
Thecode-behindfilesofallWebFormspagesintheprojectarecompiledintoprojectdynamiclinklibrary(.dll)files.The.aspxpagefilewillalsobecompiled,butthecompilationmethodisslightlydifferent.Whenauserbrowsestoan.aspxpageforthefirsttime,ASP.NETautomaticallygeneratesa.NETclassfilethatrepresentsthepageandcompilesitintoanother.dllfile.Theclassgeneratedforthe.aspxpageinheritsfromthecode-behindclassthatiscompiledintotheproject's.dllfile.WhenauserrequeststheURLofaWebpage,the.dllfilewillrunontheserveranddynamicallygenerateHTMLoutputforyourpage.Formoreinformation,seeWebFormsPageHandling.
FormoreinformationonhowtoconstructaWebFormspage,seeWebFormsCodeModel.
Mitä tehtäviä WebForms-sivu auttaa sinua suorittamaan?
Webapplicationprogrammingbringssomespecialproblems.Whenprogrammingtraditionalclient-basedapplications,youusuallydon’tWillencountertheseproblems.Thesechallengesinclude:
Implementamulti-styleWebuserinterface.Forauserinterfacewithacomplexlayoutandalargeamountofdynamiccontentandfull-featureduserinteractionobjects,itwillbedifficultandlaborioustousebasicHTMLfunctionstodesignandimplement.Particularlydifficultistocreatemulti-styleuserinterfacesforapplicationsthatmayrunonmultipledifferentbrowsersandclientdeviceplatforms.
Theseparationofclientandserver.InaWebapplication,theclient(browser)andtheserveraredifferentprograms,andtheyusuallyrunondifferentcomputers(evenondifferentoperatingsystems).Therefore,thetwopartsthattogethermakeuptheapplicationshareverylittleinformation;theycancommunicate,butusuallyonlyexchangesmallpiecesofsimpleinformation.
Statelessexecution.Whenawebserverreceivesarequestforapage,itwillfindthepage,processit,sendittothebrowser,anddiscardallpageinformation.Iftheuserrequeststhesamepageagain,theserverrepeatstheentireprocess:reprocessingthepagefromthebeginning.Inotherwords,theserverwillnotrememberthepagesithasprocessed.Therefore,iftheapplicationneedstomaintaininformationaboutacertainpage,thisbecomesaproblemthatmustbesolvedintheapplicationcode.
Unknownclientfunction.Inmanycases,webapplicationscanbeaccessedbymultipleusersusingdifferentbrowsers.Browsershavedifferentfunctions,soitisdifficulttocreateanapplicationthatwillworkequallywellonallbrowsers.
Thecomplexityofdataaccess.Readingandwritingdatasourceslocatedintraditionalwebapplicationscanbecomplicatedandconsumealotofresources.
Complexityinscalability.Inmanycases,duetothelackofcompatibilitybetweendifferentcomponentsoftheapplication,Webapplicationsdesignedwithexistingmethodsfailtoachievethegoalofscalability.Forapplicationswithashortdevelopmentcycle,thisisoftentheonlyplacethatwillleadtofailure.
Tosolvethesewebapplicationproblems,itmaytakealotoftimeandeffort.WebformpagesandASP.NETpageframeworksdealwiththeseproblemsthroughthefollowingaspects:
Intuitiveandconsistentobjectmodel.TheASP.NETpageframeworkprovidesanobjectmodelthatenablesyoutotreattheformasawhole,ratherthanseparateclientandservermodules.Inthismodel,youcanprogramtheforminamoreintuitivewaythaninatraditionalWebapplication,includingtheabilitytosetthepropertiesoftheformelementsandrespondtoevents.Inaddition,ASP.NETservercontrolsareanabstractmodelbasedonthephysicalcontentoftheHTMLpageandthedirectinteractionbetweenthebrowserandtheserver.Generally,youcanuseservercontrolsinthesamewaythatyouusecontrolsinclientapplications,regardlessofhowtocreateHTMLtodisplayandprocessthecontrolsandtheircontents.
Event-drivenprogrammingmodel.TheWebFormspagebringsafamiliareventhandlerwritingmodeltoWebapplications,whichisusedtowriteeventhandlersforeventsthatoccurontheclientorserver.TheASP.NETpageframeworkabstractsthismodelsothatthebasicmechanismsforcapturingeventsontheclient,transmittingthemtotheserver,andinvokingappropriatemethodsareallautomaticandinvisibletotheimplementer.Thisresultsinaclear,easy-to-writecodestructurethatsupportsevent-drivendevelopment.
Intuitivestatusmanagement.TheASP.NETpageframeworkautomaticallyhandlesthestatemaintenancetasksoftheformanditscontrols.Itenablesyoutomaintainthestateofapplication-specificinformationinanexplicitway.Thisstatemanagementcanbeachievedwithoutusingalargeamountofserverresources,andcanbeachievedbysendingacookietothebrowserornotbysendingacookietothebrowser.
Abrowser-independentapplication.TheASP.NETpageframeworksupportsthecreationofallapplicationlogicontheserver,eliminatingtheneedforyoutoexplicitlycodefordifferencesinbrowsers.However,itstillallowsyoutoautomaticallytakeadvantageofbrowser-specificfeaturesbywritingclientcodetoprovideenhancedperformanceandaricherclientexperience.
.NETFrameworkcommonlanguageruntimesupport.ASP.NETpageframeisatechnologyofASP.NET.ASP.NETisbasedonthe.NETFramework,sotheentireframeworkcanbeusedinanyASP.NETapplication.Youcanuseanylanguagecompatiblewiththeruntime(includingMicrosoftVisualBasic,VisualC#,andJScript.NET)toauthorapplications.Inaddition,dataaccessissimplifiedthroughthedataaccessinfrastructureprovidedbythe.NETFramework(includingADO.NET).
.NETFrameworkcanscaleserverperformance.TheASP.NETpageframeworkenablesyoutoeffectivelyscaleaWebapplicationfromacomputerwithonlyoneprocessortoamulti-computer"Webfarm"withouttheneedforthelogicoftheapplicationComplexchanges.