1.web part 通讯
web parts可以相互通讯,提供者发布接口,订阅者通过接口获得数据,webpartmanager 管理通讯,从提供者获得接口,向订阅者发布接口,通讯可以是静态的,也可以是动态的,connectionszone 提供后期绑定的ui
通讯提供者
实现方法返回接口,方法特性 [connectionprovider]
[connectionprovider ("zip code", "zipcodeprovider")]
public izipcode getzipcodeinterface ()
{
return this; // assumes control implements izipcode
}
// izipcode.getzipcode implementation
public string getzipcode ()
{
return _zip;
}通讯订阅者
实现方法接收接口参数,方法特性 [connectionconsumer]
[connectionconsumer ("zip code", "zipcodeconsumer")]
public void getizipcodeinterface (izipcode provider)
{
string zip = provider.getzipcode (); // get zip code from provider
}静态通讯方式
在 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
{
get { return _stocks; }
set { _stocks = value; }
}
shared personalization
[personalizable (personalizationscope.-shared)] persists properties on shared basis
string _stocks; // e.g., "msft,intc,amzn"
[webbrowsable]
[personalizable (personalizationscope.shared)]
public string stocks
{
get { return _stocks; }
set { _stocks = value; }
}
个性化服务是基于provider模式
使用 sql server provider
<configuration>
<system.web>
<webparts>
<personalization defaultprovider="aspnetsqlpersonalizationprovider" />
</webparts>
</system.web>
</configuration>4 定制web parts
增加自定义操作
public class mywebpart : webpart
{
public override webpartverbcollection verbs
{
get {
ensurechildcontrols ();
webpartverb verb =
new webpartverb (new webparteventhandler (onclearresults));
verb.text = "clear results";
webpartverb[] verbs = new webpartverb[] { verb };
return new webpartverbcollection (base.verbs, verbs);
}
}
void onclearresults (object sender, webparteventargs args) { }
}5.导出web part
webpart.exportmode属性,webpartexportmode.none (默认),webpartexportmode.all
webpartexportmode.nonsensitivedata,all” 及 “nonsensitivedata” 增加导出操作以便web part可以被导出
仅[personalizable] 属性,personalizableattribute.issensitive识别 “sensitive” 属性
导出所有属性
public class mywebpart : webpart
{
public mywebpart ()
{
exportmode = webpartexportmode.all;
}
}导出所选择的属性 public class mywebpart : webpart
{
public mywebpart ()
{
exportmode = webpartexportmode.nonsensitivedata;
}
// this property will be exported
[personalizable (personalizationscope.user, false)]
public string zipcode
{ }
// this one will not
[personalizable (personalizationscope.user, true)]
public string socialsecuritynumber
{ }
}
新闻热点
疑难解答
图片精选