1.WebPartManager 控件
Web Parts的总控中心,管理 Web Parts及区域的列表管理页面状态 (比如显示状态),当页面状态时发生改变时触发事件,协助Web Parts间的通讯,管理个性化等.
<asp:WebPartManager ID="WebPartManager1" RunAt="server" />
2.WebPartZone 控件
在 Web Parts页面中定义区域,定义每个区域当中Web Part的默认显示样式及布局.
<asp:WebPartZone ID="WeatherZone"
DragHighlightColor="244,198,96" RunAt="server">
<PartTitleStyle BackColor="#2254B1" ForeColor="White" />
<PartStyle BorderColor="#81AAF2" BorderStyle="Solid" BorderWidth="1px" />
<ZoneTemplate>
<!-- Web Parts declared here -->
</ZoneTemplate>
</asp:WebPartZone>
3.Web Part Chrome
标题框及Web Part的边框,通过 WebPartZone 定义其外观.
4.Web Parts
在 WebPartZone中定义的控件;Web controls, user controls, custom controls
未实现IWebPart接口的控件将封装进GenericWebParts
增加以下属性: Title, Description, etc.
<ZoneTemplate>
<asp:Calendar Title="Calendar" ID="Calendar1" RunAt="server" />
<user:Weather Title="Weather" ID="Weather1" RunAt="server" />
<custom:Search Title="Search" ID="Search1" RunAt="server" />
</ZoneTemplate>
5.WebPartManager.DisplayMode
设置或者获取页面的显示模式
BrowserDisplayMode “正常的” 显示模式,无法编辑(默认)
DesignDisplayMode 允许拖拽式布局编辑
EditDisplayMode 允许编辑Web Part的外观及行为
CatalogDisplayMode 允许将Web Part添加在另外的页面上
ConnectDisplayMode 允许Web Parts之间进行通讯
![](https://ghd258.cnblogs.com/Images/OutliningIndicators/None.gif)
6.DisplayMode 事件
WebPartManager.DisplayModeChanging 指示显示模式是否要发生改变
WebPartDisplayModeCancelEventArgs 获得新的显示模式并且允许控制者取消这种改变
WebPartManager.DisplayModeChanged 指示显示模式是否已经发生改变
WebPartDisplayModeEventArgs 得到原来的显示模式
7.其它的区域类型
WebPartZones 定义基本的页面显示内容,在任何时间均显示,其它区域允许页面可以被编辑,根据显示模式有条件得进行显示.
CatalogZone 允许用户在页面上添加Web Part
EditorZone 允许用户更改Web Part的属性及布局
ConnectionsZone 允许用户建立Web Part之间的通讯
8.CatalogZone 控件
允许Web Part可以交互式的进行添加,包含一个或者多个 CatalogPart 控件
PageCatalogPart 显示页面上已经删除的Web Part的列表
DeclarativeCatalogPart 显示声明在 <WebPartsTemplate>中的Web Part的列表
ImportCatalogPart 允许从 .WebPart文件中导入的Web Part
![](https://ghd258.cnblogs.com/Images/OutliningIndicators/None.gif)
声明 CatalogZone
<asp:CatalogZone ID="CatalogZone1" Runat="server">
<ZoneTemplate>
<asp:PageCatalogPart ID="PageCatalogPart1" Runat="server" />
<asp:DeclarativeCatalogPart ID="DeclarativeCatalogPart1" Runat="server">
<WebPartsTemplate>
<!-- Declarative Web Parts go here -->
</WebPartsTemplate>
</asp:DeclarativeCatalogPart>
<asp:ImportCatalogPart ID="ImportCatalogPart1" Runat="server" />
</ZoneTemplate>
</asp:CatalogZone>
9.EditorZone控件
允许交互式的对 Web parts进行更改,包含一个或者多个 EditorPart 控件
AppearanceEditorPart 提供修改标题及其它界面相关属性的UI
BehaviorEditorPart 提供修改行为属性的UI
LayoutEditorPart 提供修改Web Part的显示状态,区域及区域索引的UI
PropertyGridEditorPart 提供修改定制属性的UI
![](https://ghd258.cnblogs.com/Images/OutliningIndicators/None.gif)
声明 EditorZone
<asp:EditorZone ID="EditorZone1" Runat="server">
<ZoneTemplate>
<asp:AppearanceEditorPart ID="AppearanceEditorPart1" Runat="server" />
<asp:BehaviorEditorPart ID="BehaviorEditorPart1" Runat="server" />
<asp:LayoutEditorPart ID="LayoutEditorPart1" Runat="server" />
</ZoneTemplate>
</asp:EditorZone>
10.PropertyGridEditorPart
允许修改自定义属性的UI显示标记为 [WebBrowsable]的属性
string _stocks; // e.g., "MSFT,INTC,AMZN"
[WebBrowsable]
public string Stocks
![](https://ghd258.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://ghd258.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
{
![](https://ghd258.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
get
{ return _stocks; }
![](https://ghd258.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
set
{ _stocks = value; }
}
1.Web Part 通讯
Web Parts可以相互通讯,提供者发布接口,订阅者通过接口获得数据,WebPartManager 管理通讯,从提供者获得接口,向订阅者发布接口,通讯可以是静态的,也可以是动态的,ConnectionsZone 提供后期绑定的UI
通讯提供者实现方法返回接口,方法特性 [ConnectionProvider]
[ConnectionProvider ("Zip Code", "ZipCodeProvider")]
public IZipCode GetZipCodeInterface ()
![](https://ghd258.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://ghd258.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
{
return this; // Assumes control implements IZipCode
}
![](https://ghd258.cnblogs.com/Images/OutliningIndicators/None.gif)
// IZipCode.GetZipCode implementation
public string GetZipCode ()
![](https://ghd258.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://ghd258.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
{
return _zip;
}
通讯订阅者
实现方法接收接口参数,方法特性 [ConnectionConsumer]
[ConnectionConsumer ("Zip Code", "ZipCodeConsumer")]
public void GetIZipCodeInterface (IZipCode provider)
![](https://ghd258.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://ghd258.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
{
string zip = provider.GetZipCode (); // Get zip code from provider
![](https://www.cnblogs.com/Images/dot.gif)
}
静态通讯方式
在 WebPartManager的 <StaticConnections> 元素中定义,最终用户无法修改
<asp:Connection>的实例
<asp:WebPartManager ID="WebPartManager1" Runat="server">
<StaticConnections>
<asp:Connection ID="ZipCodeConnection" Runat="server"
ProviderID="Weather1" ProviderConnectionPointID="ZipCodeProvider"
ConsumerID="News1" ConsumerConnectionPointID="ZipCodeConsumer" />
</StaticConnections>
</asp:WebPartManager>
2.ConnectionsZone 控件
提供供Web Part进行通讯的UI,最终用户,而不是开发人员创建通讯关系
<asp:ConnectionsZone ID="ConnectionsZone1"
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"
[WebBrowsable]
[Personalizable]
public string Stocks
![](https://ghd258.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://ghd258.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
{
![](https://ghd258.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
get
{ return _stocks; }
![](https://ghd258.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
set
{ _stocks = value; }
}
![](https://ghd258.cnblogs.com/Images/OutliningIndicators/None.gif)
Shared Personalization
[Personalizable (PersonalizationScope.-Shared)] persists properties on shared basis
string _stocks; // e.g., "MSFT,INTC,AMZN"
![](https://ghd258.cnblogs.com/Images/OutliningIndicators/None.gif)
[WebBrowsable]
[Personalizable (PersonalizationScope.Shared)]
public string Stocks
![](https://ghd258.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://ghd258.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
{
![](https://ghd258.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
get
{ return _stocks; }
![](https://ghd258.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
set
{ _stocks = value; }
}
![](https://ghd258.cnblogs.com/Images/OutliningIndicators/None.gif)
个性化服务是基于Provider模式
使用 SQL Server Provider
<configuration>
<system.web>
<webParts>
<personalization defaultProvider="AspNetSqlPersonalizationProvider" />
</webParts>
</system.web>
</configuration>
4 定制Web Parts
增加自定义操作
public class MyWebPart : WebPart
![](https://ghd258.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://ghd258.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
{
public override WebPartVerbCollection Verbs
![](https://ghd258.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
![](https://ghd258.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
get
{
EnsureChildControls ();
WebPartVerb verb =
new WebPartVerb (new WebPartEventHandler (OnClearResults));
verb.Text = "Clear Results";
![](https://ghd258.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
WebPartVerb[] verbs = new WebPartVerb[]
{ verb };
return new WebPartVerbCollection (base.Verbs, verbs);
}
}
![](https://ghd258.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://ghd258.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
void OnClearResults (object sender, WebPartEventArgs args)
{
}
![](https://www.cnblogs.com/Images/dot.gif)
}
5.导出Web Part
WebPart.ExportMode属性,WebPartExportMode.None (默认),WebPartExportMode.All
WebPartExportMode.NonSensitiveData,All” 及 “NonSensitiveData” 增加导出操作以便Web Part可以被导出
仅[Personalizable] 属性,PersonalizableAttribute.IsSensitive识别 “sensitive” 属性
导出所有属性
public class MyWebPart : WebPart
![](https://ghd258.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://ghd258.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
{
public MyWebPart ()
![](https://ghd258.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
ExportMode = WebPartExportMode.All;
}
![](https://www.cnblogs.com/Images/dot.gif)
}
导出所选择的属性
public class MyWebPart : WebPart
![](https://ghd258.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://ghd258.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
{
public MyWebPart ()
![](https://ghd258.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
ExportMode = WebPartExportMode.NonSensitiveData;
}
![](https://ghd258.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
// This property will be exported
[Personalizable (PersonalizationScope.User, false)]
public string ZipCode
![](https://ghd258.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
}
![](https://ghd258.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
// This one will not
[Personalizable (PersonalizationScope.User, true)]
public string SocialSecurityNumber
![](https://ghd258.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
}
![](https://www.cnblogs.com/Images/dot.gif)
}