Webový formulář

Úvod

WebFormsisoneofthreeprogrammingmodelsforcreatingASP.NETwebsitesandWebapplications.

TheothertwoprogrammingmodesareWebPagesandMVC(ModelViewController).

WebForm je nejstarší model programování ASP.NET. Je to webová stránka řízená událostmi, která integruje HTML, ovládací prvky serveru a kód serveru.

WebFormsiscompiledandexecutedontheserver,andthentheservergeneratesHTMLanddisplaysitasawebpage.

WebFormshashundredsofWebcontrolsandWebcomponentsusedtocreateuser-drivenwebsiteswithdataaccess.

Funkce

BasedonMicrosoftASP.NETtechnology.Inthistechnology,thecoderunningontheserverdynamicallygeneratesWebpageoutputtothebrowserorclientdevice.FormoreinformationaboutASP.NET,pleaserefertoASP.NETTechnicalBackgroundÚvod.

  • Compatiblewithallbrowsersormobiledevices.TheWebFormspageautomaticallyrendersthecorrectHTMLthatconformstothebrowserforthestyle,layout,andotherfunctions.Inaddition,youcanalsochoosetodesigntheWebFormspagetorunonaspecificbrowser(suchasMicrosoftInternetExplorer5)andtakeadvantageofthefeaturesofthemulti-stylebrowserclient.Web form

  • Compatiblewithanylanguagesupportedbythe.NETcommonlanguageruntime,includingMicrosoftVisualBasic,MicrosoftVisualC#andMicrosoftJScript.NET.

  • BasedonMicrosoft.NETFramework.Itprovidesalltheadvantagesoftheframework,includinghostingenvironment,typesafetyandinheritance.

  • InVisualStudio,itissupportedbypowerfulrapidapplicationdevelopment(RAD)tools,whichareusedtodesignandprogramforms.

  • ItcanbeextendedwithcontrolsthatprovideRADfunctionsforWebdevelopment,allowingyoutoquicklycreatemulti-styleuserinterfaces.

  • Beflexiblebecauseyoucanadduser-createdcontrolsandthird-partycontrolstothem.

Komponenty

IntheWebformpage,userinterfaceprogrammingisdividedintotwodifferentparts:visualcomponentsandlogic.IfyouhaveusedtoolslikeVisualBasicandVisualC++before,youwillagreethatthereissuchadivisionbetweenthevisualpartoftheformandthecodethatinteractswithitbehindtheform.

ThevisualelementiscalledtheWebform"page"(page).ThistypeofpageconsistsofafilecontainingstaticHTMLand/orASP.NETservercontrols.

Webformpagesareusedascontainersforstatictextandcontrolstobedisplayed.UsingtheVisualStudioWebFormDesignerandASP.NETservercontrols,youcandesigntheformthewayyouwouldinanyVisualStudioapplication.Formoreinformation,seeControlsavailableonWebFormspages.

Logika stránky webového formuláře se skládá z kódu, který je vytvořen při interakci s formulářem. Logika programování je umístěna v souboru odlišném od souboru uživatelského rozhraní. Tento soubor se nazývá "kód-za"souborem a má rozšíření".aspx.vb"nebo".aspx.cs".

Struktura souborů

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.

Jaké úkoly vám stránka WebForms pomůže splnit?

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.

Související články
HORNÍ