关于WebPart控件的应用说明

WebPart学习

内容:

       功能简介

       webpart的五个模式

       自定义webpart部件

一、Webpart功能简介

1.  自定义页面内容

2.  自定义页面布局

3.  导入、导出webpart

4.  在不同部件间建立通信

5.  管理和个性化的设置

二、创建Webpart

1.  用现成web控件建立

2.  自定义webpart

继承自WebPart

重要方法:

public override void RenderControl(HtmlTextWriter writer)

三、WebPart的模式:

                WebPartManager1.DisplayMode=WebPartManager.BrowseDisplayMode;

                WebPartManager1.DisplayMode=WebPartManager.DesignDisplayMode;

                WebPartManager1.DisplayMode = WebPartManager.EditDisplayMode;

                WebPartManager1.DisplayMode = WebPartManager.CatalogDisplayMode;

                WebPartManager1.DisplayMode = WebPartManager.ConnectDisplayMode;

对于后四个模式要使用下面的web.config中的个性化配置才能启用

    <webParts enableExport="true">

      <personalization>

        <authorization>

          <allow users="gong" verbs="enterSharedScope"/>

        </authorization>

      </personalization>

</webParts>

1.       浏览模式:

显示部件,不能作其它操作

2.       设计模式

可以删除,拖放部件

3.       编辑模式

可以删除,拖放部件

修改webpart的相关外观、行为和属性

4.       目录模式

支持导入、导出功能,添加webpart控件

在目录模式中可以导出一个webpart

       1.设置web.config

    <webParts enableExport="true">

      <personalization>

        <authorization>

          <allow users="gong" verbs="enterSharedScope"/>

        </authorization>

      </personalization>

</webParts>

2.设置webpart控件的ExportMode属性为非None

 

5.       连接模式

多个webpart间数据的通信

Webpart连接:

1.  设置两个WebPart间的通讯接口

    public interface ITestWord

    {

        string TestText

        {

            get;

            set;

        }

    }

2.  实现提供者webpart

    public class TempWebpart : WebPart,ITestWord

     

  [Personalizable(true),WebBrowsable(true)]

        public string TestText   //ItestWord接口数据实现

         标记提供者函数

        [ConnectionProvider("TestWordProvider","TestWordProvider")]

        public ITestWord ProvideTest()

        {

            return this;

    }

3.  实现订阅者webpart

    public class TestConsumer : WebPart

         //标记订阅者函数 

      [ConnectionConsumer("TestWordConsumer","TestWordConsumer")]

        public void GetTest(ITestWord testWord)

 

4.  界面设置

静态连接:

        <asp:WebPartManager ID="WebPartManager1" runat="server">

            <StaticConnections>

                <asp:WebPartConnection ID="tt1" ProviderID="temp1" ConsumerID="testconsumer1"

                 ProviderConnectionPointID="TestWordProvider" ConsumerConnectionPointID="TestWordConsumer" />

            </StaticConnections>

        </asp:WebPartManager>

     动态连接:

       <asp:WebPartManager ID="WebPartManager1" runat="server">

          </asp:WebPartManager>之间没有内容

     下面的设置一样

<asp:WebPartZone ID="WebPartZone3" runat="server">

            <ZoneTemplate>

                <test:tempwebpart id="temp1" runat="server" />

            </ZoneTemplate>

        </asp:WebPartZone>

        <asp:WebPartZone ID="WebPartZone4" runat="server">

            <ZoneTemplate>

                <test:testconsumer ID="testconsumer1" runat="server" />

            </ZoneTemplate>

        </asp:WebPartZone>

posted @ 2008-12-24 15:42  funnyzak  阅读(361)  评论(0编辑  收藏  举报