DEV335 ASPNET Web s介绍 第二部分_第1页
DEV335 ASPNET Web s介绍 第二部分_第2页
DEV335 ASPNET Web s介绍 第二部分_第3页
DEV335 ASPNET Web s介绍 第二部分_第4页
DEV335 ASPNET Web s介绍 第二部分_第5页
已阅读5页,还剩27页未读, 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、DEV335: ASP.NET Web Forms介绍, 第二部分,张宁 Software Design Engineer Content Management ServerMicrosoft Corporation,为什么使用ASP.NET Web Forms?,基于控件, 事件驱动执行模型的Web UI 快速应用开发(RAD)“VB for the Web” 清晰的功能封装 比ASP更少代码 通过CLR运行native代码 Visual Basic, C#, JScript 比ASP更高性能 与ASP应用同时运行(side-by-side) Web Forms 使用 “.ASPX” 扩展名

2、,相关专题,DEV335 Web Forms介绍, 第一部分 DEV331 黑带Web Forms DEV333 创建服务器控件: 关键概念,第一部分内容,基础: Web Form工作原理 服务器端控件(Server Controls) 用户控件(User Controls),第二部分内容,Web UI 编程 Data Binding in Web Forms 顶制服务器端控件(Custom Server Control),Web UI 编程,页面控件树(Page Control Tree),Page类创建一个多层次控件树(hierarchical tree of controls ) Pag

3、e是树的根节点 Static text由LiteralControl类表示 页面是通过顺序调用控件树中每个控件的Render()方法生成的 用Trace显示页面生成,控件树, 第一步ASP.NET control tags are parsed, Enter : ,控件树, 第二步Controls are assembled into a tree,_PAGE System.Web.UI.Page,ctrl0 System.Web.UI.LiteralControl,ctrl1 System.Web.UI.HtmlControls.HtmlForm,ctrl3 System.Web.UI.Li

4、teralControl,ctrl4 System.Web.UI.WebControls.TextBox,ctrl5 System.Web.UI.LiteralControl,ctrl2 System.Web.UI.LiteralControl,RENDER ORDER,控件树, 第三步Page is rendered,_PAGE Renders as: ctrl0nn ctrl1 ctrl3 n Enter Name:n ctrl4 ctrl5 n ctrl2 nn,用Trace演示控件树 Using Trace To Display The Control Tree,demo,操作控件树M

5、anipulate Control Tree,把控件插入父节点的Controls集合 得到一个控件实例: Dim btn1 as New Button()btn1.Text = Click Me 插入控件层次树: myPanel.Controls.Add (btn1),用页面控件树构造动态Web UI,demo,Data Binding In Web Forms,Web Forms Data Binding,提供一种简单,声明(declarative)的方式联系(bind) Web UI元素与数据 “Simple” binding to a single property Or directl

6、y into the page “List” binding to a data source DataGrid, DropDownList, etc. 支持多种数据源(data source) 但是 单向snapshot模型 需用代码更新数据源,Simple Binding 语法,第一步: Set bindings Declaratively (in HTML): / 第二步: Call DataBind Sub Page_Load(s As Object, e As EventArgs) Label1.DataBind() End Sub,Simple Binding 例子, Sub Pa

7、ge_Load(s as Object, e as EventArgs) Label1.DataBind() End Sub / ,Binding Data To Lists,DataGrid, DropDownList, etc. 支持的数据源(Data Source) ADO.NET Connected: DataReader ADO.NET Cached: DataSet, DataTable, DataView 其它IEnumerable类型: ArrayList, Array Hashtable Result of a method,List Binding 语法,第一步: Set

8、bindings Declaratively (in HTML): / Imperatively (in code): DataGrid1.DataSource = ds; 第二步: Call DataBind Sub Page_Load(s As Object, e As EventArgs) DataGrid1.DataBind() End Sub,Data Binding A List Control,demo,Binding To Templated Lists,模版(Templates)可随意定制UI 定制结构, 而不仅仅是风格(style) 模版中可嵌套控件 Repeater, D

9、ataList, DataGrid 支持和非模版表(lists)同样的数据源 Container:由模版和数据生成的元素的别名 Container.DataItem “this row of data”,Templated List 例子, Sub Page_Load(s as Object, e as EventArgs) DataList1.DataSource = GetCustData() DataList1.DataBind() End Sub ,DataBinder.Eval Method,Helper method for late-binding Even in C#! bef

10、ore: after: Optional 3rd param for formatting ,Data Binding A Templated List,demo,定制服务器端控件Custom Server Controls,Custom Controls与User Controls的区别,User Controls (a.k.a., “pagelets”) 容易编写 象page一样 支持局部页面缓存(partial page caching) 限于单个应用(Application) VS.NET提供有限的design time支持 定制控件(Custom Controls) 支持多个应用 安

11、装到Global Assembly Cache (GAC) VS.NET提供丰富的design time支持,创建一个定制控件,从一个基类衍生(Derive from a base class) Control, WebControl 重载(Override)需要的方法(method) 基类封装大部分功能 在Web Form中使用定制控件 Optional: Implement interfaces to process posted data or expose events Optional: Use metadata to define persistence and designer

12、options Optional: 提供designer和安装支持,定制控件 Custom Control,demo,总结,基于控件, 事件驱动的执行(Control-based, event-driven execution) 简化开发(Simpler development) 干净代码(Cleaner code) Control Tree, Data Binding和Custom Controls是扩展您的.NET Web应用的功能和灵活性的强大途经,资源,Quickstart: 超过900+ ASP.NET例子 安装.NET Framework SDK IBuySpy例子: ASP.NET社区: ,如果您有任何问题,请上微软中文新

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论