1.Web Part 通讯
Web Parts可以相互通讯,提供者发布接口,订阅者通过接口获得数据,WebPartManager 管理通讯,从提供者获得接口,向订阅者发布接口,通讯可以是静态的,也可以是动态的,ConnectionsZone 提供后期绑定的UI
通讯提供者
实现方法返回接口,方法特性 [ConnectionProvider]
ASP.NET 2.0使用Web Part创建应用程序之二(共二)[ConnectionProvider ("Zip Code""ZipCodeProvider")]
ASP.NET 2.0使用Web Part创建应用程序之二(共二)
public IZipCode GetZipCodeInterface ()
}
通讯订阅者
实现方法接收接口参数,方法特性 [ConnectionConsumer]
ASP.NET 2.0使用Web Part创建应用程序之二(共二)[ConnectionConsumer ("Zip Code""ZipCodeConsumer")]
ASP.NET 2.0使用Web Part创建应用程序之二(共二)
public void GetIZipCodeInterface (IZipCode provider)
}
静态通讯方式
在 WebPartManager的 <StaticConnections> 元素中定义,最终用户无法修改
ASP.NET 2.0使用Web Part创建应用程序之二(共二)<asp:Connection>的实例
ASP.NET 2.0使用Web Part创建应用程序之二(共二)
<asp:WebPartManager ID="WebPartManager1" Runat="server">
ASP.NET 2.0使用Web Part创建应用程序之二(共二)  
<StaticConnections>
ASP.NET 2.0使用Web Part创建应用程序之二(共二)    
<asp:Connection ID="ZipCodeConnection" Runat="server"
ASP.NET 2.0使用Web Part创建应用程序之二(共二)      ProviderID
="Weather1" ProviderConnectionPointID="ZipCodeProvider"
ASP.NET 2.0使用Web Part创建应用程序之二(共二)      ConsumerID
="News1" ConsumerConnectionPointID="ZipCodeConsumer" />
ASP.NET 2.0使用Web Part创建应用程序之二(共二)  
</StaticConnections>
ASP.NET 2.0使用Web Part创建应用程序之二(共二)
</asp:WebPartManager>
2.ConnectionsZone 控件
提供供Web Part进行通讯的UI,最终用户,而不是开发人员创建通讯关系
ASP.NET 2.0使用Web Part创建应用程序之二(共二)<asp:ConnectionsZone ID="ConnectionsZone1"
ASP.NET 2.0使用Web Part创建应用程序之二(共二)  Runat
="server" />
3.Web Parts 个性化
Web Parts 个性化服务
自动保存相关Web Part的属性 (布局, 外观等等),自动保存标记为 PersonalizableAttribute的定制属性
PersonalizationAdministration 类提供个性化服务的API,Provider-based for flexible data storage
Per-User 个性化,[Personalizable] 为每位用户保存定制属性,string _stocks; // e.g., "MSFT,INTC,AMZN"
ASP.NET 2.0使用Web Part创建应用程序之二(共二)[WebBrowsable]
ASP.NET 2.0使用Web Part创建应用程序之二(共二)[Personalizable]
ASP.NET 2.0使用Web Part创建应用程序之二(共二)
public string Stocks
个性化服务是基于Provider模式
ASP.NET 2.0使用Web Part创建应用程序之二(共二)使用 SQL Server Provider
ASP.NET 2.0使用Web Part创建应用程序之二(共二)
<configuration>
ASP.NET 2.0使用Web Part创建应用程序之二(共二)  
<system.web>
ASP.NET 2.0使用Web Part创建应用程序之二(共二)    
<webParts>
ASP.NET 2.0使用Web Part创建应用程序之二(共二)      
<personalization defaultProvider="AspNetSqlPersonalizationProvider" />
ASP.NET 2.0使用Web Part创建应用程序之二(共二)    
</webParts>
ASP.NET 2.0使用Web Part创建应用程序之二(共二)  
</system.web>
ASP.NET 2.0使用Web Part创建应用程序之二(共二)
</configuration>
4 定制Web Parts
增加自定义操作
ASP.NET 2.0使用Web Part创建应用程序之二(共二)public class MyWebPart : WebPart
}
5.导出Web Part
WebPart.ExportMode属性,WebPartExportMode.None (默认),WebPartExportMode.All
WebPartExportMode.NonSensitiveData,All” 及 “NonSensitiveData” 增加导出操作以便Web Part可以被导出
仅[Personalizable] 属性,PersonalizableAttribute.IsSensitive识别 “sensitive” 属性
导出所有属性
ASP.NET 2.0使用Web Part创建应用程序之二(共二)public class MyWebPart : WebPart
}
导出所选择的属性
ASP.NET 2.0使用Web Part创建应用程序之二(共二)public class MyWebPart : WebPart
}

相关文章: