您好,欢迎来到纷纭教育。
搜索
您的当前位置:首页计算机论文中英文翻译

计算机论文中英文翻译

来源:纷纭教育
Asp.netOverview

WhenASPwasfirstreleased,WebprogrammingwasmoredifficultbecauseyouneededIIStoserveyourASPpages.Later,ASP.NET2.0andVisualStudio®2005madeeverythingeasierbyintroducingtheWebsitemodelofdevelopment.InsteadofcreatinganewprojectinsideVisualStudio,theWebsitemodelletsyoupointtoadirectoryandstartwritingpagesandcode.Furthermore,youcanquicklytestyoursitewiththebuilt-inASP.NETDevelopmentServer,whichhostsASP.NETinalocalprocessandobviatestheneedtoinstallIIStobegindeveloping.wewillintroduceasp.net2.0technologyfromdifferentaspects.

1.The.NETFrameworkClassLibraryASP.NETispartofMicrosoft'soverall.NETframework,whichcontainsavastsetofprogrammingclassesdesignedtosatisfyanyconceivableprogrammingneed.BecauseVisualBasic,JScript,andC++.Agreatdealofthefunctionalityoftheseprogramminglanguagesoverlaps.Forexample,foreachlanguage,youwouldhavetoincludemethodsforaccessingthefilesystem,workingwithdatabases,andmanipulatingstrings.What’smore,theselanguagescontainsimilarprogrammingconstructs,canrepresentloopsandconditionals.EventhoughthesyntaxofaconditionalwritteninVisualBasicdiffersfromthesyntaxofaconditionalwritteninC++,theprogrammingfunctionisthesame.Maintainingallthisfunctionalityformultiplelanguagesrequiresalotofwork.Wouldn'titbeeasiertocreateallthisfunctionalityonceanduseitforeverylanguage?However,The.NETFrameworkClassLibrarydoesexactlythat.Itconsistsofavastsetofclassesdesignedtosatisfyanyconceivableprogrammingneed.Forinstance,the.NETframeworkcontainsclassesforhandlingdatabaseaccess,workingwiththefilesystem,manipulatingtext,andgeneratinggraphics.Inaddition,itcontainsmorespecializedclassesforperformingtaskssuchasworkingwithregularexpressionsandhandlingnetworkprotocols.Furthermore,the.NETframeworkcontainsclassesthatrepresentallthebasicvariabledatatypessuchasstrings,integers,bytes,characters,andarrays.

1The.NETframeworkishuge.Itcontainsthousandsofclasses(over3,400).Fortunately,theclassesarenotsimplyjumbledtogether.Theclassesofthe.NETframeworkareorganizedintoahierarchyofnamespaces.

Anamespaceisalogicalgroupingofclasses.Forexample,alltheclassesthatrelatetoworkingwiththefilesystemaregatheredtogetherintotheSystem.IOnamespace.Thenamespacesareorganizedintoahierarchy(alogicaltree).AttherootofthetreeistheSystemnamespace.Thisnamespacecontainsalltheclassesforthebasedatatypes,suchasstringsandarrays.Italsocontainsclassesforworkingwithrandomnumbersanddatesandtimes.

Youcanuniquelyidentifyanyclassinthe.NETframeworkbyusingthefullnamespaceoftheclass.Forexample,touniquelyrefertotheclassthatrepresentsafilesystemfile(theFileclass),youwouldusethefollowing:

System.IO.File

System.IOreferstothenamespace,andFilereferstotheparticularclass.

TheclassescontainedinaselectnumberofnamespacesareavailableinyourASP.NETpagesbydefault.(Youmustexplicitlyimportothernamespaces.)ThesedefaultnamespacescontainclassesthatyouusemostofteninyourASP.NETapplications:System—Containallthebasedatatypesandotherusefulclassessuchasthoserelatedtogeneratingrandomnumbersandworkingwithdatesandtimes.

System.Collections—Containsclassesforworkingwithstandardcollectiontypessuchashashtables,andarraylists.

System.Collections.Specialized—

Contains

classes

that

represent

specialized

collectionssuchaslinkedlistsandstringcollections.

System.Configuration—Containsclassesforworkingwithconfigurationfiles(Web.configfiles).

System.Text—Containsclassesforencoding,decoding,andmanipulatingthecontentsofstrings.

System.Text.RegularExpressions—expressionmatchandreplaceoperations.

Contains

classes

for

performing

regular

2System.Web—ContainthebasicclassesforworkingwiththeWorldWideWeb,includingclassesforrepresentingbrowserrequestsandserverresponses.

System.Web.Caching—Containsclassesusedforcachingthecontentofpagesandclassesforperformingcustomcachingoperations.

System.Web.Security—ContainsclassesforimplementingauthenticationandauthorizationsuchasFormsandPassportauthentication.

System.Web.SessionState—Containsclassesforimplementingsessionstate.System.Web.UI—ContainthebasicclassesusedinbuildingtheuserinterfaceofASP.NETpages.

System.Web.UI.HTMLControls—ContaintheclassesfortheHTMLcontrols.System.Web.UI.WebControls—ContaintheclassesfortheWebcontrols.

YoucanchooseC#orJScript.NETorC++orVisualBasictoprogramasp.netpage.regardlessofthelanguagethatyouusetodevelopyourASP.NETpages,youneedtounderstandthatASP.NETpagesarecompiledbeforetheyareexecuted.ThismeansthatASP.NETpagescanexecuteveryquickly.ThefirsttimeyourequestanASP.NETpage,thepageiscompiledintoa.NETclass,andtheresultingclassfileissavedbeneathaspecialdirectoryonyourservernamedTemporaryASP.NETFiles.ForeachandeveryASP.NETpage,acorrespondingclassfileappearsintheTemporaryASP.NETFilesdirectory.WheneveryourequestthesameASP.NETpageinthefuture,thecorrespondingclassfileisexecuted.WhenanASP.NETpageiscompiled,itisnotcompileddirectlyintomachinecode.Instead,itiscompiledintoanintermediate-levellanguagecalledMicrosoftIntermediateLanguage(MSIL).All.NET-compatiblelanguagesarecompiledintothisintermediatelanguage.AnASP.NETpageisn'tcompiledintonativemachinecodeuntilitisactuallyrequestedbyabrowser.Atthatpoint,theclassfilecontainedintheTemporaryASP.NETFilesdirectoryiscompiledwiththe.NETframeworkJustinTime(JIT)compilerandexecuted.Themagicalaspectofthiswholeprocessisthatithappensautomaticallyinthebackground.AllyouhavetodoiscreateatextfilewiththesourcecodeforyourASP.NETpage.

2.BuildingFormswithWebServerControls

3UsingseveralofthebasicWebcontrolstorepresentstandardHTMLformelementssuchasradiobuttons,textboxes,andlistboxes.YoucanusethesecontrolsinyourASP.NETpagestocreatetheuserinterfaceforyourWebapplication.

3.PerformingFormValidationwithValidationControls

Traditionally,Webdevelopershavefacedatoughchoicewhenaddingformvalidationlogictotheirpages.Youcanaddformvalidationroutinestoyourserver-sidecode,oryoucanaddthevalidationroutinestoyourclient-sidecode.Theadvantageofwritingvalidationlogicinclient-sidecodeisthatyoucanprovideinstantfeedbacktoyourusers.Forexample,ifauserneglectstoenteravalueinarequiredformfield,youcaninstantlydisplayanerrormessagewithoutrequiringaroundtripbacktotheserver.Peoplereallylikeclient-sidevalidation.Itlooksgreatandcreatesabetteroveralluserexperience.Theproblem,however,isthatitdoesnotworkwithallbrowsers.NotallbrowserssupportJavaScript,anddifferentversionsofbrowserssupportdifferentversionsofJavaScript,soclient-sidevalidationisneverguaranteedtowork.Forthisreason,inthepast,manydevelopersdecidedtoaddalltheirformvalidationlogicexclusivelytoserver-sidecode.Becauseserver-sidecodefunctionscorrectlywithanybrowser,thiscourseofactionwassafer.Atthesametime,TheValidationcontrolsautomaticallygeneratebothclient-sideandserver-sidecode.IfabrowseriscapableofsupportingJavaScript,client-sidevalidationscriptsareautomaticallysenttothebrowser.IfabrowserisincapableofsupportingJavaScript,thevalidationroutinesareautomaticallyimplementedinserver-sidecode.

RequiringFields:TheRequiredFieldValidatorControl

YouuseRequiredFieldValidatorinaWebformtocheckwhetheracontrolhasavalue.Typically,youusethiscontrolwithaTextBoxcontrol.However,nothingiswrongwithusingRequiredFieldValidatorwithotherinputcontrolssuchasRadioButtonList.

ValidatingExpressions:TheRegularExpressionValidatorControl

4YoucanuseRegularExpressionValidatortomatchthevalueenteredintoaformfieldtoaregularexpression.Youcanusethiscontroltocheckwhetherauserhasentered,forexample,avalide-mailaddress,telephonenumber,orusernameorpassword.Samplesofhowtousearegularexpressiontoperformallthesevalidationtasksareprovidedinthefollowingsections.

ComparingValues:TheCompareValidatorControl

TheCompareValidatorcontrolperformscomparisonsbetweenthedataenteredintoaformfieldandanothervalue.Theothervaluecanbeafixedvalue,suchasaparticularnumber,oravalueenteredintoanothercontrol.

SummarizingErrors:TheValidationSummaryControl

Imaginethatyouhaveaformwith50formfields.IfyouuseonlytheValidationcontrolsdiscussedintheprevioussectionsofthischaptertodisplayerrors,seeinganerrormessageonthepagemightbedifficult.Forexample,youmighthavetoscrolldowntothe48thformfieldtofindtheerrormessage.

Fortunately,MicrosoftincludesaValidationSummarycontrolwiththeValidationcontrols.Youcanusethiscontroltosummarizealltheerrorsatthetopofapage,orwhereverelseyouwant.

4.AdvancedControlProgramming

WorkingwithViewState

Bydefault,almostallASP.NETcontrolsretainthevaluesoftheirpropertiesbetweenformposts.Forexample,ifyouassigntexttoaLabelcontrolandsubmittheform,whenthepageisrenderedagain,thecontentsoftheLabelcontrolarepreserved.Themagicofviewstateisthatitdoesnotdependonanyspecialserverorbrowserproperties.Inparticular,itdoesnotdependoncookies,sessionvariables,orapplicationvariables.ViewstateisimplementedwithahiddenformfieldcalledVIEWSTATEthatisautomaticallycreatedin

5everyWebFormsPage.Whenusedwisely,viewstatecanhaveadramaticandpositiveeffectontheperformanceofyourWebsite.Forexample,ifyoudisplaydatabasedatainacontrolthathasviewstateenabled,youdonothavetoreturntothedatabaseeachtimethepageispostedbacktotheserver.Youcanautomaticallypreservethedatawithinthepage'sviewstatebetweenformposts.

DisplayingandHidingContent

Imaginethatyouwanttobreakthetaxformintomultiplepagessothatapersonviewsonlyonepartofthetaxformatatime.YoucansettheVisibleandEnabledpropertieswithindividualcontrolsandgroupsofcontrolstohideanddisplaypagecontent.UsingtheVisibleandEnabledProperties

Everycontrol,includingbothHTMLandWebcontrols,hasavisiblepropertythatdetermineswhetherthecontrolisrendered.Whenacontrol'svisiblepropertyhasthevalue

False,thecontrolisnotdisplayedonthepage;thecontrolisnotprocessedforeither

pre-renderingorrendering.

Webcontrols(butnoteveryHTMLcontrol)haveanadditionalpropertynamedEnabled.WhenEnabledhasthevalueFalseandyouareusingInternetExplorerversion4.0orhigher,thecontrolappearsghostedandnolongerfunctions.Whenusedwithotherbrowsers,suchasNetscapeNavigator,thecontrolmightnotappearghosted,butitdoesnotfunction.

5.WebDeploymentProjects

ThebeautyoftheAsp.net2.0isthatyoucandevelopyourWebapplicationwithoutthinkingaboutpackaginganddeployment.Whenneedanotherclass,YoucanAdda.CsfiletotheApp_Codedirectoryandstartwriting.Whenwanttostorelocalizablestringsinaresourcefile,youcanadda.resxfiletotheApp_GlobalResourcesdirectoryandtypeinthestrings.Everythingjustworks;youdon'thavetothinkaboutthecompilationanddeploymentaspectatall.

Whenyouarereadytodeploy,youhaveseveraloptions.Thesimplestchoiceistocopyyourfilestoaliveserverandleteverythingbecompiledon-demand(asitwasinyourtestenvironment).Thesecondoptionistousetheaspnet_compiler.exeutilityand

6precompiletheapplicationintoabinaryrelease,whichleavesyounothingbutacollectionofassemblies,staticcontent,andconfigurationfilestopushtotheserver.Thethirdoptionistoagainuseaspnet_compiler.exe,buttocreateanupdateablebinarydeploymentwhereyour.as*xfilesremainintact(andmodifiable)andallofyourcodefilesarecompiledintobinaryassemblies.

6.C#Language

IntroductiontotheC#Languageandthe.NETFramework

C#isanelegantand

type-safeobject-orientedlanguagethatenablesdeveloperstobuildawiderangeofsecureandrobustapplicationsthatrunonthe.NETFramework.YoucanuseC#tocreate

traditionalWindowsclientapplications,XMLWebservices,distributedcomponents,client-serverapplications,databaseapplications,andmuch,muchmore.MicrosoftVisualC#2005providesanadvancedcodeeditor,convenientuserinterfacedesigners,integrateddebugger,andmanyothertoolstofacilitaterapidapplicationdevelopmentbasedonversion2.0oftheC#languageandthe.NETFramework.

C#syntaxishighlyexpressive,yetwithlessthan90keywords,itisalsosimpleandeasytolearn.Thecurly-bracesyntaxofC#willbeinstantlyrecognizabletoanyonefamiliarwithC,C++orJava.DeveloperswhoknowanyoftheselanguagesaretypicallyabletobeginworkingproductivelyinC#withinaveryshorttime.C#syntaxsimplifiesmanyofthecomplexitiesofC++whileprovidingpowerfulfeaturessuchasnullablevaluetypes,enumerations,delegates,anonymousmethodsanddirectmemoryaccess,whicharenotfoundinJava.C#alsosupportsgenericmethodsandtypes,whichprovideincreasedtypesafetyandperformance,anditerators,whichenableimplementersofcollectionclassestodefinecustomiterationbehaviorsthataresimpletousebyclientcode.

Asanobject-orientedlanguage,C#supportstheconceptsofencapsulation,inheritanceandpolymorphism.Allvariablesandmethods,includingtheMainmethod,theapplication'sentrypoint,areencapsulatedwithinclassdefinitions.Aclassmayinheritdirectlyfromoneparentclass,butitmayimplementanynumberofinterfaces.Methodsthatoverridevirtualmethodsinaparentclassrequiretheoverridekeywordasawaytoavoidaccidental

7redefinition.InC#,astructislikealightweightclass;itisastack-allocatedtypethatcanimplementinterfacesbutdoesnotsupportinheritance.

Inadditiontothesebasicobject-orientedprinciples,C#facilitatesthedevelopmentofsoftwarecomponentsthroughseveralinnovativelanguageconstructs,including:

Encapsulatedmethodsignaturescalleddelegates,whichenable

type-safeeventnotifications.

Properties,whichserveasaccessorsforprivatemembervariables.Attributes,whichprovidedeclarativemetadataabouttypesatrun

time.

InlineXMLdocumentationcomments.

IfyouneedtointeractwithotherWindowssoftwaresuchasCOMobjectsornativeWin32DLLs,youcandothisinC#throughaprocesscalled\"Interop.\"InteropenablesC#programstodojustaboutanythingthatanativeC++applicationcando.C#evensupportspointersandtheconceptof\"unsafe\"codeforthosecasesinwhichdirectmemoryaccessisabsolutelycritical.

TheC#buildprocessissimplecomparedtoCandC++andmoreflexiblethaninJava.Therearenoseparateheaderfiles,andnorequirementthatmethodsandtypesbedeclaredinaparticularorder.AC#sourcefilemaydefineanynumberofclasses,structs,interfaces,andevents.

C#programsrunonthe.NETFramework,anintegralcomponentofWindowsthatincludesavirtualexecutionsystemcalledthecommonlanguageruntime(CLR)andaunifiedsetofclasslibraries.TheCLRisMicrosoft'scommercialimplementationofthecommonlanguageinfrastructure(CLI),aninternationalstandardthatisthebasisforcreatingexecutionanddevelopmentenvironmentsinwhichlanguagesandlibrariesworktogetherseamlessly.

SourcecodewritteninC#iscompiledintoanintermediatelanguage(IL)thatconformstotheCLIspecification.TheILcode,alongwithresourcessuchasbitmapsandstrings,is

8storedondiskinanexecutablefilecalledanassembly,typicallywithanextensionof.exeor.dll.Anassemblycontainsamanifestthatprovidesinformationontheassembly'stypes,version,culture,andsecurityrequirements.

WhentheC#programisexecuted,theassemblyisloadedintotheCLR,whichmighttakevariousactionsbasedontheinformationinthemanifest.Then,ifthesecurityrequirementsaremet,theCLRperformsjustintime(JIT)compilationtoconverttheILcodeintonativemachineinstructions.TheCLRalsoprovidesotherservicesrelatedtoautomaticgarbagecollection,exceptionhandling,andresourcemanagement.CodethatisexecutedbytheCLRissometimesreferredtoas\"managedcode,\"incontrastto\"unmanagedcode\"whichiscompiledintonativemachinelanguagethattargetsaspecificsystem.Thefollowingdiagramillustratesthecompile-timeandruntimerelationshipsofC#sourcecodefiles,thebaseclasslibraries,assemblies,andtheCLR.

Languageinteroperabilityisakeyfeatureofthe.NETFramework.BecausetheILcodeproducedbytheC#compilerconformstotheCommonTypeSpecification(CTS),ILcodegeneratedfromC#caninteractwithcodethatwasgeneratedfromthe.NETversionsofVisualBasic,VisualC++,VisualJ#,oranyofmorethan20otherCTS-compliantlanguages.Asingleassemblymaycontainmultiplemoduleswrittenindifferent.NETlanguages,andthetypescanreferenceeachotherjustasiftheywerewritteninthesamelanguage.

Inadditiontotheruntimeservices,the.NETFrameworkalsoincludesanextensivelibraryofover4000classesorganizedintonamespacesthatprovideawidevarietyofusefulfunctionalityforeverythingfromfileinputandoutputtostringmanipulationtoXMLparsing,toWindowsFormscontrols.ThetypicalC#applicationusesthe.NETFrameworkclasslibraryextensivelytohandlecommon\"plumbing\"chores.

9ASP.NET概述当ASP第一次发布时,Web编程还比较困难,因为需要IIS来处理ASP页。后来,ASP.NET2.0和VisualStudio®2005通过引入网站开发模型使一切工作都变得容易了。借助该网站模型,您不必在VisualStudio中创建新项目,而是可以指向一个目录并开始编写网页和代码。此外,您还可以使用内置的ASP.NETDevelopmentServer快速测试站点,ASP.NETDevelopmentServer将ASP.NET寄宿在一个本地进程中,并消除了必须安装IIS才能进行开发这一先决条件。下面从不同的方面来介绍Asp.net2.0技术。

1.net类库

ASP.NET是微软.NETframework整体的一部分,它包含一组大量编程用的类,满足各种编程需要。因为VisualBasic、JScript和C++这些编程语言的很多功能具有重叠性。举例来说,对于每一种语言,你必须包括存取文件系统、与数据库协同工作和操作字符串的方法。此外,这些语言包含相似的编程构造。都能够使用循环语句和条件语句。即使用VisualBasic写的条件语句的语法和用C++的不一样,程序的功能也是相同的。对于多种语言来说维持这一功能需要很大的工作量。那么对所有的语言创建这种功能一次,然后把这个功能用在每一种语言中岂不是更容易。然而.NET类库不完全是那样。它含有大量的满足编程需要的类。举例来说,.NET类库不仅包含处理数据库访问的类和文件协同工作,操作文本和生成图像,而且还包含更多特殊的类用在正则表达式和处理Web协议。此外.NETframework,也包含支持所有的基本变量数据类型的类,比如:字符串、整型、字节型、字符型和数组。

.NETframework是庞大的。它包含数以千计的类。(超过3,400)幸运地是,类不是简单的堆在一起。.NETframework的类被组织成有层次结构的命名空间。

一个命名空间包含一组逻辑的类。举例来说,涉及到与文件系统协同工作的类就集合在System.IO命名空间中。命名空间被组织成一个层次结构(一棵逻辑树)。树根就是SYSTEM命名空间。这个命名空间包含基本的数据类型的所有的类,例如:字符串、数组,还包含提供随机数字和日期的类。

你通过完整的类的命名空间能唯一识别任何的类在.NETframework中的位置。例如,指定找到一个theFileclass类,按如下操作:

System.IO.文件

10System.IO指命名空间,而文件指定特定的类。

在默认情况下,在你的ASP.NET页面中,类被包含在一个选定的命名空间中这些默认的命名空间使你在ASP.NET中最常用到的。

System命名空间-包含所有的基本数据类型和其他有用的类,例如:那些关于产生随机数字和日期的类。

System.Collections命名空间-包含的类是标准的集合类,例如:哈希表,数组列表。

System.Collections.Specialized命名空间-包含特殊的集合类,例如:连接列表和字符串集合。

System.Configuration命名空间-包括Web.configfiles类。System.Text命名空间-包含编码,解码和操作字符串内容的类。

System.Text.RegularExpressions命名空间-包含的是匹配正则表达式和替代操作类。

System.Web命名空间-工作在万维网方面包含的是浏览器请求和服务器响应的类。

System.Web.Caching命名空间-包含页面缓冲内容和自定义缓冲操作的类。System.Web.Security命名空间-包含执行验证和授权,例如:窗体和密码验证的类。

System.Web.SessionState命名空间-包含执行保存状态的类。System.Web.UI命名空间-包含构建ASP.NET页面的用户接口的类。System.Web.UI.HTMLControls命名空间-包含HTML控件的类。System.Web.UI.WebControls命名空间-包含Web控件的类。

.Net支持C#,JScript.NET,C++和VisualBasic中的任一种语言作为你的编程语言来完成ASP.NET程序编写。但不管你使用什么语言开发ASP.NET页面,你需要明白ASP.NET在执行前必须编译,这就意味着ASP.NET执行速度非常快。第一次请求ASP.NET页面,页面被编译成一个.NET类,这个类文件被保存在一个特殊的目录下,这个目录的名字叫TemporaryASP.NETFiles。对于一个ASP.NET页面一个通信类文件也会出现在TemporaryASP.NETFiles目录下。以后不管任何时候你请求那个同样的ASP.NET页面,那个通信类文件就会执行。当ASP.NET页面被编译的时候,它没被直接地被编译成机器码而是被编译成了一个中间语言,名字叫MSIL,所有.NET可用的语言都被编

11译成这种中间语言。一个ASP.NET页面不会被编译成本地机器码直到它被一个浏览器访问,在那个时间点包含在TemporaryASP.NETFiles目录下的类文件用JIT编译器编译并且执行。这些迷惑的方面体现在整个过程中且都在后台运行,你必须要做的是用资源代码为你的ASP.NET页面创建一个文本文件。

2.用Web服务器控件创建窗体

用几个基本Web控件来代替标准的HTML窗体元素,例如radiobuttons、textboxes,andlistboxes.在Web应用程序中可以用这些控件创建用户界面。

3.用验证控件做页面验证

传统地,当增加验证到页面中时,会面临一个严峻的选择。你可以添加窗体页面验证规则到你的服务器端代码,也可以添加验证规则到你的客户端代码。

写验证代码到客户端代码中的优势能够及时反馈到你的用户。例如,一个使用者忽略输入一个要求检验的字段,你能够及时的显示一个错误信息而不需要返回到服务器端解决。人们喜欢客户端的验证。它能产生一种很好的效果。然而,问题是它不与所有的浏览器兼容。不是所有的浏览器支持JavaScript、不同版本的浏览器的不同版本支持JavaScript,所以客户端验证没有保障。由于这个原因,许多开发者决定添加自定义验证到服务器端。因为服务器端代码能够和任何浏览器协同工作。这样的做法是更有安全保障。同时这些验证控件会自动地产生客户端代码和服务器端代码。如果一个浏览器有能力支持JavaScript,客户端的验证脚本将会自动返回到浏览器。如果一个浏览器不支持JavaScript,那个验证规则会自动在服务器端代码中执行。

控制字段:RequiredFieldValidator控件

你可以用这个控件来检查在一个Web窗体中是否为空,典型地,你和TextBox控件一起使用这个控件。然而,这个控件也可以和其他的输入型控件结合使用,例如:RadioButtonList控件。

验证表达式:RegularExpressionValidator控件

你能使用RegularExpressionValidator控件来验证输入的值是否和定义的正则表达式相匹配。例如:你能使用这控件来检查一个用户是否输入一个合法的电子邮件地址,电话号码,用户名或密码。

比较值:CompareValidator控件

12这个CompareValidator控件用于比较一个输入的数据和另外一个值是否相同。另外一个值可能是固定值,例如:一个特定的数字或者是输入到另一个控件中的一个值。

总结错误:ValidationSummary控件

假想一个页面有50个字段假如你仅仅用上部分讨论的那些验证控件来显示错误看见一个错误在页面中将是很难的。例如:你可能需要滚动到第48个页面字段来找到这个错误信息。

幸好,微软除了包含上面提到的控件还包括ValidationSummary控件。你能用这个控件综合所有的错误信息在一个页面的上端或者你想要的任何一个地方。

4.先进的控件编程

保存浏览状态

默认地,几乎所有的ASP.NET控件都会在先前的窗体中保留他们的属性值。举例来说,如果你输入文本到一个Lebel标签上然后提交那个页面,当那个页面再次被访问时那个Lebel标签的内容将会被保存下来。浏览状态的妙处是它不依赖任何的特定服务器或浏览器的属性。尤其,它不依赖cookies,session变量、或应用程序变量。浏览状态在一个名叫做VIEWSTATE的隐藏页面中执行,这个隐藏页面自动创建每个Web窗体。当应用时,浏览状态能够在你的网站中产生艺术性的积极效果,例如:你在一个支持浏览状态的控件中显示数据库数据,你不需要每次都返回到需要反馈到服务器的数据库页面。它能够自动地保存页面里的数据状态。

显示和隐藏内容

假想把一个form变成很多页面,以便一个人每次只看那个form的一个部分。

可以设置单个控件和一组控件的VisibleandEnabled属性来隐藏和显示页面内容。

使用VisibleandEnabled属性

每个控件,包括HTML和Web控件,有一个Visible属性来决定那个控件是否可见。当一个控件的Visible是false值,那个控件就不会在页面上显示;那个控件也不会进一步运行。

13Web控件(不是每个HTML控件)还有一个叫Enabled的属性。当Enabled的属性是false值,你用的浏览器是IE4.0或更高的版本那个控件被封住了,也不起作用了,当用其他的浏览器的时候,如:网景浏览器那个控件不会被封,但它也是不起作用的。

5.Web部署项目

Asp.net2.0的魅力在于您在开发Web应用程序时无需考虑打包和部署。当需要其他类时可向App_Code目录添加一个.cs文件即可开始编写。当希望将可本地化的字符串存储在资源文件中时,可向App_GlobalResources目录添加一个.resx文件并键入字符串。一切都顺顺当当,根本就不必考虑编译和部署方面的事情。

在准备进行部署时,有多种可选方案。最简单的方案是将文件复制到主运行服务器并按要求编译每一个文件(和在测试环境中一样)。第二种方案是使用asp.net_compiler.exe实用工具将应用程序预编译为二进制版本,之后将只剩下要放到服务器上的一组程序集、静态内容和配置文件。第三种方案也使用asp.net_compiler.exe,但要创建一个可更新的二进制部署,其中.as*x文件保持不变(并且可修改),而所有代码文件都编译为二进制程序集。

6.C#语言

C#是一种简洁、类型安全的面向对象的语言,开发人员可以使用它来构建在.NETFramework上运行的各种安全、可靠的应用程序。使用C#,您可以创建传统的Windows客户端应用程序、XMLWebservices、分布式组件、客户端-服务器应用程序、数据库应用程序以及很多其他类型的程序。MicrosoftVisualC#2005提供高级代码编辑器、方便的用户界面设计器、集成调试器和许多其他工具,以在C#语言版本2.0和.NETFramework的基础上加快应用程序的开发。

C#语法表现力强,只有不到90个关键字,而且简单易学。C#的大括号语法使任何熟悉C、C++或Java的人都可以立即上手。了解上述任何一种语言的开发人员通常在很短的时间内就可以开始使用C#高效地工作。C#语法简化了C++的诸多复杂性,同时提供了很多强大的功能,例如可为空的值类型、枚举、委托、匿名方法和直接内存访问,这些都是Java所不具备的。C#还支持泛型方法和类型,从而提供了更出色的类型安全和性能。C#还提供了迭代器,允许集合类的实现者定义自定义的迭代行为,简化了客户端代码对它的使用。

作为一种面向对象的语言,C#支持封装、继承和多态性概念。所有的变量和方法,

14包括Main方法(应用程序的入口点),都封装在类定义中。类可能直接从一个父类继承,但它可以实现任意数量的接口。重写父类中的虚方法的各种方法要求override关键字作为一种避免意外重定义的方式。在C#中,结构类似于一个轻量类;它是一种堆栈分配的类型,可以实现接口,但不支持继承。

除了这些基本的面向对象的原理,C#还通过几种创新的语言结构加快了软件组件的开发,其中包括:

封装的方法签名(称为委托),它实现了类型安全的事件通知。属性(Property),充当私有成员变量的访问器。

属性(Attribute),提供关于运行时类型的声明性元数据。内联XML文档注释。

在C#中,如果需要与其他Windows软件(如COM对象或本机Win32DLL)交互,可以通过一个称为“Interop”的过程来实现。互操作使C#程序能够完成本机C++应用程序可以完成的几乎任何任务。在直接内存访问必不可少的情况下,C#甚至支持指针和“不安全”代码的概念。

C#的生成过程比C和C++简单,比Java更为灵活。没有单独的头文件,也不要求按照特定顺序声明方法和类型。C#源文件可以定义任意数量的类、结构、接口和事件。

C#程序在.NETFramework上运行,它是Windows的一个必要组件,包括一个称为公共语言运行时(CLR)的虚拟执行系统和一组统一的类库。CLR是Microsoft的公共语言基础结构(CLI)的一个商业实现。CLI是一种国际标准,是用于创建语言和库在其中无缝协同工作的执行和开发环境的基础。

用C#编写的源代码被编译为一种符合CLI规范的中间语言(IL)。IL代码与资源(如位图和字符串)一起作为一种称为程序集的可执行文件存储在磁盘上,通常具有的扩展名为.exe或.dll。程序集包含清单,它提供关于程序集的类型、版本、区域性和安全要求等信息。

执行C#程序时,程序集将加载到CLR中,这可能会根据清单中的信息执行不同的操作。然后,如果符合安全要求,CLR执行实时(JIT)编译以将IL代码转换为本机机器指令。CLR还提供与自动垃圾回收、异常处理和资源管理有关的其他服务。由CLR执行的代码有时称为“托管代码”,它与编译为面向特定系统的本机机器语言的“非托管代码”相对应。下图演示了C#源代码文件、基类库、程序集和CLR的编译

15时与运行时的关系。

语言互操作性是.NETFramework的一个关键功能。因为由C#编译器生成的IL代码符合公共类型规范(CTS),因此从C#生成的IL代码可以与从VisualBasic、VisualC++、VisualJ#的.NET版本或者其他20多种符合CTS的语言中的任何一种生成的代码进行交互。单一程序集可能包含用不同.NET语言编写的多个模块,并且类型可以相互引用,就像它们是用同一种语言编写的。

除了运行时服务,.NETFramework还包含一个由4000多个类组成的内容详尽的库,这些类被组织为命名空间,为从文件输入和输出到字符串操作、到XML分析、到Windows窗体控件的所有内容提供多种有用的功能。典型的C#应用程序使用.NETFramework类库广泛地处理常见的“日常”任务。

16

因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- fenyunshixun.cn 版权所有 湘ICP备2023022495号-9

违法及侵权请联系:TEL:199 18 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务