1. Web Part Communication
Web parts can communicate with each other. The provider publishes an interface, the subscriber obtains data through the interface, and the webpartmanager manages communication. The interface is obtained from the provider and the interface is released to the subscriber. The communication can be static, it can also be dynamic. connectionszone provides the later bound UI
Communication provider
Implementation Method return interface, method features [connectionprovider] [Connectionprovider ( " Zip code " , " Zipcodeprovider " )]
Public Izipcode getzipcodeinterface ()
{
Return This;//Assumes control implements izipcode
}
// Izipcode. getzipcode implementation
Public String Getzipcode ()
{
Return_ Zip;
}
Communication subscriber
Interface Parameters for receiving implementation methods, method features [connectionconsumer][Connectionconsumer ( " Zip code " , " Zipcodeconsumer " )]
Public Void Getizipcodeinterface (izipcode provider)
{
StringZip=Provider. getzipcode ();//Get zip code from provider
}
Static Communication Mode
Defined in the <staticconnections> element of webpartmanager, the end user cannot modify< ASP: Connection > Instance
< 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 Control
Provides the UI for Web Part communication. end users, instead of developers, create communication relationships.<ASP: connectionszoneID= "Connectionszone1"
Runat= "Server" />
3. Web parts personalization
Web parts personalized service
Automatically save the attributes (layout, appearance, and so on) of Related Web parts, and automatically save the Custom Attributes marked as personalizableattribute.
Personalizationadministration class provides APIs for personalized services, provider-based for flexible data storage
Per-User Personalization, [personalizable] saves custom attributes for each user, 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 ;}
}
Personalized service is based on the provider Mode Use SQL Server Provider
< Configuration >
< System . Web >
< Webparts >
< Personalization Defaultprovider = "Aspnetsqlpersonalizationprovider" />
</ Webparts >
</ System. Web >
</ Configuration >
4. Custom Web parts
Add custom operations Public Class Mywebpart: webpart
{
Public Override Webpartverbcollection Verbs
{
Get {
Ensurechildcontrols ();
Webpartverb =
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. Export Web Part
Webpart. exportmode attribute, webpartexportmode. None (default), webpartexportmode. All
Webpartexportmode. nonsensitivedata, all "and" nonsensitivedata "add export operations so that Web parts can be exported
Only [personalizable] attribute, and personalizableattribute. issensitive identifies "sensitive" attribute
Export all attributes
Public Class Mywebpart: webpart
{
PublicMywebpart ()
{
Exportmode=Webpartexportmode. All;
}
}
Export selected properties
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
{}
}