Въведение
WebFormsisoneofthreeprogrammingmodelsforcreatingASP.NETwebsitesandWebapplications.
TheothertwoprogrammingmodesareWebPagesandMVC(ModelViewController).
WebForm е най-старият модел за програмиране на ASP.NET. Това е управлявана от събития уеб страница, която интегрира HTML, сървърни контроли и сървърен код.
WebFormsiscompiledandexecutedontheserver,andthentheservergeneratesHTMLanddisplaysitasawebpage.
WebFormshashundredsofWebcontrolsandWebcomponentsusedtocreateuser-drivenwebsiteswithdataaccess.
Характеристика
BasedonMicrosoftASP.NETtechnology.Inthistechnology,thecoderunningontheserverdynamicallygeneratesWebpageoutputtothebrowserorclientdevice.FormoreinformationaboutASP.NET,pleaserefertoASP.NETTechnicalBackgroundВъведение.
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.
Компоненти
IntheWebformpage,userinterfaceprogrammingisdividedintotwodifferentparts:visualcomponentsandlogic.IfyouhaveusedtoolslikeVisualBasicandVisualC++before,youwillagreethatthereissuchadivisionbetweenthevisualpartoftheformandthecodethatinteractswithitbehindtheform.
ThevisualelementiscalledtheWebform"page"(page).ThistypeofpageconsistsofafilecontainingstaticHTMLand/orASP.NETservercontrols.
Webformpagesareusedascontainersforstatictextandcontrolstobedisplayed.UsingtheVisualStudioWebFormDesignerandASP.NETservercontrols,youcandesigntheformthewayyouwouldinanyVisualStudioapplication.Formoreinformation,seeControlsavailableonWebFormspages.
Страницата с логиката на уебформуляра се състои от код, който е създаден от вас, за да взаимодействате с формуляра.
Файлова структура
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.
Какви задачи ви помага да изпълните страницата WebForms?
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.