版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
MSDN
开发员最好的和必备的资源站在微软技术最前沿!为开发者创建的网络提供一年12期的光盘资料分三个级别开发库—最新的开发文档,示例代码专业版—开发库+全部微软操作系统+SDK+DDK宇宙版—专业版+其他所有微软产品目的:为开发人员提供最先进的技术资料,产品,并提供相互帮助的机会
IntroductionTo
ActiveServerPages.NET
张炜
Evangelist
MicrosoftCorporation
weizha@OverviewIntroducingASP.NETCreatingWebFormsWebFormsDataBindingUserControlsUsingWebServicesASPToday(thePros)TheleadingwebappdevelopmentplatformNearly1milliondevelopersusingASPtodaySimpleandapproachablemodelforwebdeveloperstogetstartedNocompilersrequired–“justhitsave”EasytouselanguagesandobjectmodelWellestablisheddevelopersupportbaseGoodbook/consulting/conferencesupportASPToday(theCons)WeaktoolsPoorlayout,debuggers,profilersConfusingsecurityarchitectureDoesn’tworkwellforInternetappsPoordeploymentCOMcomponentsanightmareMetabaseconfigurationoptionsconfusingScalabilitychallengesNowebfarmorcachinginfrastructureIntroducingASP.NETYourexistingASPskillsstillapply,buttherearelotsmorefeaturestoleveragePlatformforcreatingscalableWebapplicationsandservicesImproveddeveloperproductivityModular,factoredarchitectureEasiertodeployEnhancedreliability&availabilityImprovedperformance&scalabilityASP.NETFeaturesMultipleLanguageSupportIncreasedPerformanceCompiledcodeCacheClassesandNamespacesServerControlsWebServicesASP.NETFeatures(continued)ImprovedSecurityGreaterScalabilityCookie-lessSessionsEasyConfigurationandDeploymentASP.NETWebPageDemoPartDeclarative,PartCodeDeclarative"tags"HTML,servercontrolstags,statictextUnlikeASP,goodseparationprovidedbetweencodeandtags<tags>Form1.aspxcode<tags>Form1.aspxcodeForm1.vbsinglefileseparatefiles("code-behind")DynamicallyCompiledASPXFileRequestASPXEngineParseGen’d
Page
Class
GenerateResponseRequestInstantiateResponseCode-
behind
class
PageClassInstantiate,Process&RenderCompile24001200160080040028002000PCMagazineNileApplicationTestPagesServedperSecond8-CPUCompaqProLiant8500ApplicationServer8-CPUCompaqProLiant8500DatabaseServerWebSphere
3.5JSP
RHLinux7.0
Oracle8i3707896038CPU4CPU2CPUMicrosoft
ASP
(VBScript)
SQLSvr2000330748637Microsoft
ASP.NET
(C#)
SQLSvr2000198911542781ASP.NETPagescaninclude…CodeBlocksStaticTextControlTagsHTMLTagsDirectivesDataBinding
ExpressionsRenderblocks<%=…%>Servercomments<%----%>ClientscriptCreatingWebFormsWhatAreWebForms?WhatAreServerControls?TypesofServerControlsHowDoServerControlsWork?ControleventprocessingDemoWhatAreWebForms?.aspxextension@PageDirectiveFrameworkIsanObjectModelDenotedbytherunat="server"AttributeContainClient-sideandServer-sideCodeContainHTMLandServerControls<Formrunat="server"></Form><%@PageLanguage=“c#"%>WhyWebForms?Newcontrol-based,event-drivenexecutionmodelforWebUI"VBfortheWeb"CleanlyencapsulatedfunctionalityMuchlesscoderequiredthanASPExecutedviaCLRasnativecodeVB,C#,JscriptFasterexecutionthanASPWebFormsuse".ASPX"extensionRunsside-by-sidewithASPapplicationsWhatAreServerControls?Server-programmableObjectsDenotedbyTagwiththerunat="server"AttributeEncapsulateBothBehaviorandRenderingFullyDeclarativeRenderDifferentHTMLtoSupportMultipleBrowsersorotherWebClientsTypesofServerControlsHTMLControlsExistwithintheSystem.Web.UI.HtmlControlsnamespaceWebControlsExistwithinthe
System.Web.UI.WebControlsnamespace<inputtype="text"id="txtName"runat="server"><spanid="spnStarter"runat="server">starter</span><asp:TextBoxid="txtName"runat="server"Text="[EntryKeywords]"/>HtmlControl
DemoWhatAreWebControls?WebControlsIntrinsiccontrols
asp:list,asp:button,asp:checkbox,asp:tableInputValidationcontrols
asp:RangeValidator,asp:RegularExpressionValidatorRichcontrols
asp:calendar,asp:adrotatorList-boundcontrols
asp:datagrid,asp:repeater,asp:datalistHowDoServerControlsWork?Declaredwithrunat="server"AttributeWhentheASP.NETPageisExecuted:CreatesactionandmethodattributesofformAddsuniqueidandnameattributestocontrolsAddsvalueattributetocontrolsAddsahiddencontroltotheformtosaveviewstateinformation<inputtype="text"id="text2"runat="server"><html><scriptlanguage=“C#“runat=server>voidSubmitBtn_Click(Objectsender,EventArgsE){ Message.Text=“Hi“+Name.Text;}</script><body><formrunat=server><h3>Name:<asp:textboxid=“Name“runat=server/> <asp:buttontype=submittext=“LookUp“ OnClick=“SubmitBtn_Click“runat=server/><p> <asp:labelid=“Message“runat=server/></form></body></html>OtherMicrosoftControlsMobileControlsRendersWebUItoMobiledevicesincludingWAPphones,MsftMobileExplorerphones,CEdevices,etc.Download:/downloads/default.asp?URL=/code/sample.asp?url=/msdn-files/027/001/516/msdncompositedoc.xmlInternetExplorerControlsTakeadvantageofIE5.5DHTMLBehaviorsforricherclientexperienceTabStrip,TreeViewandToolbarMoreinfo:/downloads/samples/Internet/ASP_DOT_NET_ServerControls/WebControls/sample.aspInternetExplorerControlDemoControleventprocessingEventsare:TriggeredontheclientHandledinservercodeRequiresapostbacktothesamepageViewStatehelpsrestorecontroltoit’spreviousstateImplementedasahiddenformfieldDisablevia:EnableViewState=falseTip:DataBindingresetscontrolstateHandlingControlEventsWireupthehandleronthetag:
<asp:buttonid=btn1onclick="btn1_Click" runat=server>Or,incode(VS.NETdoesthisautomatically)btn1.Click+=newEventHandler(btn1_click);Eventhandlercode:
publicvoidbtn1_Click(senderObject,eEventArgs){ Message.Text="Button1clicked" }Page/ControlEventExecutionPage_LoadPage_UnloadTextbox1_ChangedButton1_ClickControlEvents1.ChangeEvents2.ActionEventsPageisloaded,controlhierarchyinitializedPageisdisposedControlhierarchyisrenderedPage_LoadDetailsPage_LoadfiresoneveryrequestUsePage.IsPostBacktoexecuteconditionallogicExample:PublicvoidPage_Load(senderObject,eEventArgs)If(!Page.IsPostBack)
{‘executesonlyoninitialpageloadMessage.Text="initialvalue“}ThePageControlTreeThePageclasscreatesahierarchicaltreeofcontrolsPageistherootofthetreeStatictextisrepresentedbytheLiteralControlclassinthehierarchyThepageisrenderedbycallingRender()oneachcontrolinthetreeSowhat?ProgrammaticallyaddcontrolsPredictseventandrenderingorderExample
ASP.NETsource<%@Pagelanguage="C#"%><html><body>
<formrunat=server>Enter:
<asp:TextBoxrunat=server>YourName
</asp:TextBox></form></body></html>Example(cont’d)
Resultingcontroltree__PAGE System.Web.UI.Pagectrl0System.Web.UI.LiteralControlctrl1System.Web.UI.HtmlControls.HtmlFormctrl3System.Web.UI.LiteralControlctrl4System.Web.UI.WebControls.TextBoxctrl5System.Web.UI.LiteralControlctrl2System.Web.UI.LiteralControlManipulatingtheControlTreeInsertcontrolsintotheControlscollectionofit’sparentCookupaninstanceofacontrol
Buttonbtn1=newButton()
btn1.Text="ClickMe"
Insertintothecontrolhierarchy:
myPanel.Controls.Add(btn1)WebFormsDataBindingWebFormsDataBindingProvidesasimple,declarativewaytobindWebUIelementstodataSupportsbindingtoanydatasourceDataSets,DataTables,DataReadersCollections(Arrays,Hashtable,etc.)XMLBut…OnewaysnapshotmodelRequirescodetoupdatethedatasourceDataBindingSyntaxFirststep:declarethebindingsDeclaratively(inHTML):
<%#custID%>Imperatively(incode):
DropDownList1.DataSource=myArrayList;
Secondstep:CallDataBind
SubPage_Load(sAsObject,eAsEventArgs)
DropDownList1.DataBind()
EndSub
SupportedDataSourcesADO.NETConnected:DataReaderADO.NETDisconnected:DataSet,DataTable,DataViewAlsootherIEnumerabletypes:Arraylist,ArrayHastableResultofamethodDataBindinginTemplatesTemplatesenable“Lookless”UICustomizestructure–notjuststyleControlscanbeusedwithintemplatesNotlimitedtolistsordatabindingControlsmayexposeanynumberofthemDataBinder.Evalhelperforlate-bindingEveninC#!
<%#DataBinder.Eval(Container.DataItem,"Price","{0:c}")%>ContainerContainer:aliasfortheitemcreatedfromthetemplate+data.Item
thecontainingcontrol.DataItemthisrowofdata.ItemIndex
indexinItemscollectionExamples:<%#Container.ItemIndex%><%#Container.DataItem("Name")%><%#Container.DataItem("Price")%>DataBinding
DemoUserControlsUserControlsServercontrols,authoredlikepagesEnablesfullencapsulationSupportsnestedcontrolsSeparatecodenamespaceSeparatecodelanguageGreatwaytopartitionworkGreatwaytoreuseworkacrossmultiplepagesandapplicationsExposingAnObjectModelUsercontrolsexposeanobjectmodelProperties,Fields,Events,MethodsExample:<scriptlanguage=“c#"runat="server">publicstringColor="blue"</script><fontcolor=<%=Color%>> Thisisasimplemessageusercontrol</font><%@Register%>DirectiveRegistersUserControlforuseonaWebFormspage:
<%@Register
TagPrefix="Acme"
TagName="Message"
Src="mycontrol1.ascx"
%>
<Acme:MessageText="Hello"runat="server"/>WhatisaWebService?MostcommonmetaphorforaccessinginformationisthroughawebbrowserWebbrowserisnotenough…AwebserviceisprogrammableapplicationlogicaccessibleviastandardWebprotocolsProgrammable…Availabletoavarietyofclients(platformindependent)Standardpro
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2024建筑设计合同范文
- 智能化健身科技促进个人健康管理考核试卷
- 旅行社职工合同范例
- 橡胶制品的市场渗透与战略合作考核试卷
- 废钢供应合同范例
- 天然气综合利用与能源转型考核试卷
- 2021年主管护师(儿科护理)资格考试题库
- 2021年中医助理医师考试题库及答案解析(单选题)
- 服装设计师的创造力与创新能力考核试卷
- 物业停车位合同模板
- 工业厂房设计规划方案
- 安全生产检查咨询服务投标方案(技术方案)
- 急性粒细胞白血病护理查房
- 公司安全部门简介
- 危废仓库建筑合同
- 中医外科临床诊疗指南 烧伤
- (2024年)《口腔医学美学》课件
- 物业公司消防知识培训方案
- 门诊护患沟通技巧(简)
- GH/T 1419-2023野生食用菌保育促繁技术规程灰肉红菇
- ISO9001:2015标准内容讲解
评论
0/150
提交评论