ASP.NET 2.0使用Web Part建立應用程式之二(共二)

來源:互聯網
上載者:User
asp.net|web|程式|建立

1.Web Part 通訊
Web Parts可以相互連訊,提供者發布介面,訂閱者通過介面獲得資料,WebPartManager 管理通訊,從提供者獲得介面,向訂閱者發布介面,通訊可以是靜態,也可以是動態,ConnectionsZone 提供後期綁定的UI
通訊提供者
實現方法返回介面,方法特性 [ConnectionProvider]
[ConnectionProvider ("Zip Code", "ZipCodeProvider")]
public IZipCode GetZipCodeInterface ()
{
    return this; // Assumes control implements IZipCode
}

// IZipCode.GetZipCode implementation
public string GetZipCode ()
{
    return _zip;
}通訊訂閱者
實現方法接收介面參數,方法特性 [ConnectionConsumer]
[ConnectionConsumer ("Zip Code", "ZipCodeConsumer")]
public void GetIZipCodeInterface (IZipCode provider)
{
    string zip = provider.GetZipCode (); // Get zip code from provider
     
}靜態通訊方式
在 WebPartManager的 <StaticConnections> 元素中定義,終端使用者無法修改
<asp:Connection>的執行個體
<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 控制項
提供供Web Part進行通訊的UI,終端使用者,而不是開發人員建立通訊關係
<asp:ConnectionsZone ID="ConnectionsZone1"
  Runat="server" />3.Web Parts 個人化
Web Parts 個人化服務
自動儲存相關Web Part的屬性 (布局, 外觀等等),自動儲存標記為 PersonalizableAttribute的定製屬性
PersonalizationAdministration 類提供個人化服務的API,Provider-based for flexible data storage
Per-User 個人化,[Personalizable] 為每位使用者儲存定製屬性,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; }
}
個人化服務是基於Provider模式
使用 SQL Server Provider
<configuration>
  <system.web>
    <webParts>
      <personalization defaultProvider="AspNetSqlPersonalizationProvider" />
    </webParts>
  </system.web>
</configuration>4 定製Web Parts
增加自訂動作
public class MyWebPart : WebPart
{
    public override WebPartVerbCollection Verbs
    {
        get {
            EnsureChildControls ();
            WebPartVerb verb =
                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.匯出Web Part
WebPart.ExportMode屬性,WebPartExportMode.None (預設),WebPartExportMode.All
WebPartExportMode.NonSensitiveData,All” 及 “NonSensitiveData” 增加匯出操作以便Web Part可以被匯出
僅[Personalizable] 屬性,PersonalizableAttribute.IsSensitive識別 “sensitive” 屬性
匯出所有屬性
public class MyWebPart : WebPart
{
    public MyWebPart ()
    {
        ExportMode = WebPartExportMode.All;
    }
 
}匯出所選擇的屬性 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
    {  }
 
}

 



相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.