ASP. NET 2.0 using Web part to create Application 2 (2 in total)

Source: Internet
Author: User
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
{}

}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.