Web form

Introduction

WebFormsisoneofthreeprogrammingmodelsforcreatingASP.NETwebsitesandWebapplications.

TheothertwoprogrammingmodesareWebPagesandMVC(ModelViewController).

WebFormsistheoldestASP.NETprogrammingmodel.Itisanevent-drivenwebpagethatintegratesHTML,servercontrols,andservercode.

WebFormsiscompiledandexecutedontheserver,andthentheservergeneratesHTMLanddisplaysitasawebpage.

WebFormshashundredsofWebcontrolsandWebcomponentsusedtocreateuser-drivenwebsiteswithdataaccess.

Features

BasedonMicrosoftASP.NETtechnology.Inthistechnology,thecoderunningontheserverdynamicallygeneratesWebpageoutputtothebrowserorclientdevice.FormoreinformationaboutASP.NET,pleaserefertoASP.NETTechnicalBackgroundIntroduction.

  • 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.

Components

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

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

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

Thelogicofawebformpageconsistsofcode,whichiscreatedbyyoutointeractwiththeform.Theprogramminglogicislocatedinafiledifferentfromtheuserinterfacefile.Thisfileiscalleda"code-behind"fileandhasanextensionof".aspx.vb"or".aspx.cs".Thelogicwritteninthecode-behindfilecanbewritteninVisualBasicorVisualC#.

Filestructure

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.

WhattasksdoestheWebFormspagehelpyouaccomplish?

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.

Related Articles
TOP