Use Web parts to create personalized ASP. NET 2.0 applications

Source: Internet
Author: User

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.

  1. 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.

    1. <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.

  2. 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.

    1. <Asp: webpartzone id = "webpartzone1" runat = "server">
    2. <Zonetemplate>
    3. </Zonetemplate>
    4. </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.

  3. 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

    1. <Asp: catalogzone id = "catalogzone1" runat = "server">
    2. <Zonetemplate>
    3. <Asp: pagecatalogpart id = "pagecatalogpart1" runat = "server"/>
    4. <Asp: declarativecatalogpart id = "declarativecatalogpart1" runat = "server">
    5. <Webpartstemplate>
    6. <Asp: button id = "button1" runat = "server" text = "button"/>
    7. </Webpartstemplate>
    8. </ASP: declarativecatalogpart>
    9. </Zonetemplate>
    10. </ASP: catalogzone>

     

    The catalogzone control allows you to add Web parts interactively. It can contain one or more catalogpart controls.

  4. 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.

    1. <Asp: editorzone id = "editorzone1" runat = "server">
    2. <Zonetemplate>
    3. <Asp: appearanceeditorpart id = "appearanceeditorpart1" runat = "server"/>
    4. <Asp: behavioreditorpart id = "behavioreditorpart1" runat = "server"/>
    5. <Asp: layouteditorpart id = "layouteditorpart1" runat = "server"/>
    6. <Asp: propertygrideditorpart id = "propertygrideditorpart1" runat = "server"/>
    7. </Zonetemplate>
    8. <Asp: editorzone>

     

    Propertygrideditorpart allows you to modify the UI of a custom attribute and display the attribute marked as [webbrowsable.

    1. Int myvar;
    2. [Webbrowsable]
    3. Public int myproperty
    4. {
    5. Get {return myvar ;}
    6. Set {myvar = value ;}
    7. }

     

    The editzone control allows interactive changes to Web parts. It can contain one or more editpart controls.

  5. 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.

    1. <Asp: webpartmanager id = "webpartmanager1" runat = "server">
    2. <Staticconnections>
    3. <Asp: webpartconnection id = "myconnection" consumerid = "myconsumer" providerid = "myprovider" consumerconnectionpointid = "myconsumerpoint" providerconnectionpointid = "myproviderpoint"/>
    4. </Staticconnections>
    5. </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.

    1. <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.

  6. 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:

    1. <Webparts>
    2.  
    3. <Personalization defaultprovider = "aspnetsqlpersonalizationprovider"/>
    4. </Webparts>

     

  7. 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:

    1. Public class mywebpart: webpart
    2. {
    3. Public override webpartverbcollection Verbs
    4. {
    5. Get
    6. {
    7. Ensurechildcontrols ();
    8. Webpartverb = new webpartverb (New webparteventhandler (onclearresults ));
    9. Verb. Text = "clear results ";
    10. Webpartverb [] verbs = new webpartverb [] {verb };
    11. Return new webpartverbcollection (base. verbs, verbs );
    12. }
    13. }
    14.  
    15. Void onclearresult (Object sender, webparteventargs ARGs ){...}
    16. }

     

  8. 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.

    1. Public mywebpart ()
    2. {
    3. This. exportmode = webpartexportmode. All;
    4. }

     

    You can also select attributes to be exported and define them in the attribute declaration.

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.