ASP.NET2.0學習8--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>

 

 
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章