Web parts is ASP in Microsoft Visual Studio 2005. NET 2.0 is one of the new features. Web parts is the framework for building portal-style applications. It inherits from the mature mode of SharePoint Portal Server, you can use the smallest code to create richer performance, for example, you can use the drag-and-drop method to create a page layout. All the controls related to it are in the namespace system. Web. UI. webcontrols. webparts.
- Webpartmanager Control
Webpartmanager is the master control center of Web parts. It can manage the list of Web parts and regions, manage the Page Status, trigger events when the page status changes, assist in communication between Web parts, and manage personalization.
Each page has only one webpartsmanager instance with no UI.
- <Asp: webpartmanager id = "webpartmanager1" runat = "server"/>
Webpartmanger. displaymode
Set or obtain the display mode of the page
Browserdisplaymode: "normal" display mode, which cannot be edited (default)
Designdisplaymode: The drag-and-drop Layout mode is allowed.
Editdisplaymode: allows you to edit the appearance and behavior of Web parts.
Catalogdisplaymode: allows you to add a Web part to another page.
Connectdisplaymode: allows communication between Web parts.
Displaymode event
When the displaymode changes, the webpartmanager. displaymodechanging event is triggered. The webpartdisplaymodecanceleventargs parameter obtains the new display mode and allows the Controller to cancel the change.
When the dispalymode has changed, the webpartmanager. displaymodechanged event is triggered. The parameter webpartdispalymodeeventargs gets the original display mode.
- Webpartzone Control
Webpartzone is a region defined on the Web parts page. It defines the default display style and layout of Web parts in each region.
- <Asp: webpartzone id = "webpartzone1" runat = "server">
- <Zonetemplate>
- </Zonetemplate>
- </ASP: webpartzone>
Web Part Chrome is the title bar and border of the Web part. It defines its appearance and operations through webpartzone.
You can define various controls in webpartzone, such as Web controls, user controls, and custom controls. Controls that do not implement the iwebpart interface will be encapsulated into genericwebparts, and the following attributes need to be added, such as title and description.
- Catalogzone Control
Pagecatalogpart: displays the list of deleted Web parts on the page.
Declarativecatalogpart: displays the list of Web parts declared in
Importcatalogpart: Web Part imported in the. webpart File
- <Asp: catalogzone id = "catalogzone1" runat = "server">
- <Zonetemplate>
- <Asp: pagecatalogpart id = "pagecatalogpart1" runat = "server"/>
- <Asp: declarativecatalogpart id = "declarativecatalogpart1" runat = "server">
- <Webpartstemplate>
- <Asp: button id = "button1" runat = "server" text = "button"/>
- </Webpartstemplate>
- </ASP: declarativecatalogpart>
- </Zonetemplate>
- </ASP: catalogzone>
The catalogzone control allows you to add Web parts interactively. It can contain one or more catalogpart controls.
- Editorzone Control
Appearanceeditorpart: provides the ability to modify the title, that is, other interface-related attributes.
Uibehavioreditorpart: Provides
Ui layouteditorpart: allows you to modify the display status, region, and Region index of a Web part.
Uipropertygrideditorpart: Provides the UI for modifying custom attributes.
- <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"/>
- <Asp: propertygrideditorpart id = "propertygrideditorpart1" runat = "server"/>
- </Zonetemplate>
- <Asp: editorzone>
Propertygrideditorpart allows you to modify the UI of a custom attribute and display the attribute marked as [webbrowsable.
- Int myvar;
- [Webbrowsable]
- Public int myproperty
- {
- Get {return myvar ;}
- Set {myvar = value ;}
- }
The editzone control allows interactive changes to Web parts. It can contain one or more editpart controls.
- Web Part Communication
The communication provider must implement the method return interface. The method features [connectionprovider]
The subscriber of communication needs to implement the method receiving interface. The method features [connectionconsumer]
Work Mode:
1. webpartmanager calls the [connectionprovider] Method
2. webpartmanager obtains the interface from the response parameters
3. webpartmanager calls the [connectionconsumer] method to pass the interface to the subscriber.
4. The Subscriber uses the given interface to communicate with the publisher.
Static Communication Mode:
The communication relationship between webparts is defined in the staticconnections element of webpartmanager during design, and the end user cannot modify it.
- <Asp: webpartmanager id = "webpartmanager1" runat = "server">
- <Staticconnections>
- <Asp: webpartconnection id = "myconnection" consumerid = "myconsumer" providerid = "myprovider" consumerconnectionpointid = "myconsumerpoint" providerconnectionpointid = "myproviderpoint"/>
- </Staticconnections>
- </ASP: webpartmanager>
Dynamic Communication Mode:
Use the connectionzone control to provide the UI for Web Part communication. End users can customize the communication between webparts during runtime.
- <Asp: connectionszone id = "connectionszone1" runat = "server"/>
Web parts can communicate with each other in a way similar to events. The provider publishes an interface, and the subscriber obtains data through the interface. Communication is managed by webpartmanger, which obtains the interface from the provider and publishes the interface to the subscriber. Communication can be static, defined during design, or dynamic, that is, the connectionszone provides the later bound UI at runtime.
- Web parts personalization
Using the Web Part personalization service, you can automatically save the attributes (layout, appearance, and so on) of Related Web parts, and automatically save Custom Attributes marked as personalizableattribute.
The personalizationadministration class also provides a series of personalized service APIs for us to call.
You can also provide personalized services for each user. You only need to declare the attribute as [personalizable.
You can also declare the attribute as [personalizable (personalizationscope. Shared)], so that this attribute can be shared by every user.
The Web parts personalized service is based on the provider mode. Beta1 provides two providers:
Accesspersonalizationprovider (ACCESS)
Aqlpersonalizationprovider (SQL Server)
In beta2, accseepersonalizationprovider has been removed.
You can also use a custom provider to add support for other data sources.
If you use the provider of SQL Server, you must add the declaration in the web. config file:
- <Webparts>
-
- <Personalization defaultprovider = "aspnetsqlpersonalizationprovider"/>
- </Webparts>
- Custom Web parts
Any control can be run as Web parts, but it is best to use a control inherited from webpart. In this way, you can get better applications. For example, you can control the title of the control and other UI-related attributes, the allowclose, allowzonechange, allowminimize, and other behavior attributes of the control, which can be applied to role-based security features, you can also add custom operations, including exporting 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 onclearresult (Object sender, webparteventargs ARGs ){...}
- }
- Export Web Part
Webpart. exprotmode attribute
Webpartexportmode. None (default)
Webpartexportmode. All allow exporting all data
Webpartexportmode. nonsensitivedata allows exporting non-sensitive data
You can define the Web part Export attribute in the constructor.
- Public mywebpart ()
- {
- This. exportmode = webpartexportmode. All;
- }
You can also select attributes to be exported and define them in the attribute declaration.