WebPart.ExportMode 屬性

定義

取得或設定是否可匯出全部、一些 WebPart 控制項的屬性,或全部都不匯出。

public:
 virtual property System::Web::UI::WebControls::WebParts::WebPartExportMode ExportMode { System::Web::UI::WebControls::WebParts::WebPartExportMode get(); void set(System::Web::UI::WebControls::WebParts::WebPartExportMode value); };
[System.Web.UI.Themeable(false)]
[System.Web.UI.WebControls.WebParts.Personalizable(System.Web.UI.WebControls.WebParts.PersonalizationScope.Shared)]
public virtual System.Web.UI.WebControls.WebParts.WebPartExportMode ExportMode { get; set; }
[<System.Web.UI.Themeable(false)>]
[<System.Web.UI.WebControls.WebParts.Personalizable(System.Web.UI.WebControls.WebParts.PersonalizationScope.Shared)>]
member this.ExportMode : System.Web.UI.WebControls.WebParts.WebPartExportMode with get, set
Public Overridable Property ExportMode As WebPartExportMode

屬性值

WebPartExportMode

其中一個 WebPartExportMode 值。 預設為 None

屬性

例外狀況

指定的值不是其中一個 WebPartExportMode 值。

控制項已經載入,而控制項的個人化範圍設定為 User 範圍。

範例

下列程式碼範例示範 如何使用 ExportMode 屬性。 請注意,針對匯出程式碼範例正常運作,您也必須更新 Web.config 檔案加上屬性enableExport="true"<webParts>項目,如 < 備註 > 一節所示。

此範例的第一個部分包含名為 TextDisplayWebPart 之控制項的程式碼。 這個控制項與類別概觀的 Example 區段中找到的 WebPart 自訂控制項相同,不同之處在于它會將屬性新增 PersonalizableTextDisplayWebPart.ContentText 屬性,以便匯出屬性。 請注意,屬性宣告包含 參數的值 true isSensitive ,這表示屬性會標示為敏感性資料以供匯出之用。 若要執行程式碼範例,您必須編譯此原始程式碼。 您可以明確地編譯它,並將產生的元件放在網站的 Bin 資料夾或全域組件快取中。 或者,您可以將原始程式碼放在月臺的 App_Code 資料夾中,其將在執行時間動態編譯。 此程式碼範例假設您將原始程式碼編譯成元件、將它放在 Web 應用程式的 Bin 子資料夾中,並在網頁中使用 指示詞參考元件 Register 。 如需示範這兩種編譯方法的逐步解說,請參閱逐步解說 :開發和使用自訂 Web 服務器控制項

using System;
using System.Security.Permissions;
using System.Web;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

namespace Samples.AspNet.CS.Controls
{
  [AspNetHostingPermission(SecurityAction.Demand, 
    Level=AspNetHostingPermissionLevel.Minimal)]
  [AspNetHostingPermission(SecurityAction.InheritanceDemand, 
    Level=AspNetHostingPermissionLevel.Minimal)]
  public class TextDisplayWebPart : WebPart
  {
    private String _contentText = null;
    TextBox input;
    Label DisplayContent;
    const string _subTitle = "Contoso, Ltd";

    public TextDisplayWebPart()
    {
      this.AllowClose = false;
    }

    [
      Personalizable(PersonalizationScope.User, true),
      WebBrowsable()
    ]
    public String ContentText
    {
      get { return _contentText; }
      set { _contentText = value; }
    }

    protected override void CreateChildControls()
    {
      Controls.Clear();
      DisplayContent = new Label();
      DisplayContent.BackColor = 
        System.Drawing.Color.LightBlue;
      DisplayContent.Text = this.ContentText;
      this.Controls.Add(DisplayContent);
      input = new TextBox();
      this.Controls.Add(input);
      Button update = new Button();
      update.Text = "Set Label Content";
      update.Click += new EventHandler(this.submit_Click);
      this.Controls.Add(update);
      ChildControlsCreated = true;
    }

    private void submit_Click(object sender, EventArgs e)
    {
      // Update the label string.
      if (!string.IsNullOrEmpty(input.Text))
      {
        _contentText = input.Text + @"<br />";
        input.Text = String.Empty;
        DisplayContent.Text = this.ContentText;
      }
    }
  }
}
Imports System.Security.Permissions 
Imports System.Web
Imports System.Web.UI.WebControls 
Imports System.Web.UI.WebControls.WebParts

Namespace Samples.AspNet.VB.Controls

<AspNetHostingPermission(SecurityAction.Demand, _ 
  Level := AspNetHostingPermissionLevel.Minimal)> _ 
<AspNetHostingPermission(SecurityAction.InheritanceDemand, _
  Level := AspNetHostingPermissionLevel.Minimal)> _ 
Public Class TextDisplayWebPart 
  Inherits WebPart
  Private _contentText As String = Nothing
  Private input As TextBox
  Private DisplayContent As Label 
  Private Const _subTitle as String = "Contoso, Ltd"
  
  
  Public Sub New()  
    Me.AllowClose = False 
  End Sub 
  
  <Personalizable(PersonalizationScope.User, True), _
   WebBrowsable()>  _ 
  Public Property ContentText() As String 
    Get 
      Return _contentText 
    End Get 
    Set 
      _contentText = value
    End Set 
  End Property
    
  Protected Overrides Sub CreateChildControls() 
    Controls.Clear()
    DisplayContent = New Label()
    DisplayContent.Text = Me.ContentText
    DisplayContent.BackColor = _
      System.Drawing.Color.LightBlue
    Me.Controls.Add(DisplayContent) 
    input = New TextBox() 
    Me.Controls.Add(input)
    Dim update As New Button()
    update.Text = "Set Label Content" 
    AddHandler update.Click, AddressOf Me.submit_Click
    Me.Controls.Add(update) 
    ChildControlsCreated = True 
  
  End Sub 

  Private Sub submit_Click(ByVal sender As Object, _
                           ByVal e As EventArgs)  
    ' Update the label string.
    If input.Text <> String.Empty Then
      _contentText = input.Text & "<br />"
      input.Text = String.Empty 
      DisplayContent.Text = Me.ContentText
    End If
  
  End Sub 
  
End Class 

End Namespace

範例的第二個部分示範如何參考 TextDisplayWebPart ASP.NET 網頁中的控制項。 請注意,在宣告式標記中,ExportMode屬性值設定為All,這表示會匯出甚至與敏感值的屬性。

<%@ page language="C#" %>
<%@ register tagprefix="aspSample" 
             Namespace="Samples.AspNet.CS.Controls" 
             Assembly="TextDisplayWebPartCS"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <title>ASP.NET Example</title>
</head>
<body>
  <form id="Form1" runat="server">
    <asp:webpartmanager id="WebPartManager1" runat="server" />
    <asp:webpartzone
      id="WebPartZone1"
      runat="server"
      title="Zone 1"
      PartChromeType="TitleAndBorder">
        <parttitlestyle font-bold="true" ForeColor="#3300cc" />
        <partstyle
          borderwidth="1px"   
          borderstyle="Solid"  
          bordercolor="#81AAF2" />
        <zonetemplate>
          <aspSample:TextDisplayWebPart 
            runat="server"   
            id="textwebpart" 
            title = "Text WebPart" 
            ExportMode="All" 
            />
        </zonetemplate>
    </asp:webpartzone>
    <br />
  </form>
</body>
</html>
<%@ page language="VB" %>
<%@ register tagprefix="aspSample" 
             Namespace="Samples.AspNet.VB.Controls" 
             Assembly="TextDisplayWebPartVB"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <title>ASP.NET Example</title>
</head>
<body>
  <form id="Form1" runat="server">
    <asp:webpartmanager id="WebPartManager1" runat="server" />
    <asp:webpartzone
      id="WebPartZone1"
      runat="server"
      title="Zone 1"
      PartChromeType="TitleAndBorder">
        <parttitlestyle font-bold="true" ForeColor="#3300cc" />
        <partstyle
          borderwidth="1px"   
          borderstyle="Solid"  
          bordercolor="#81AAF2" />
        <zonetemplate>
          <aspSample:TextDisplayWebPart 
            runat="server"   
            id="textwebpart" 
            title = "Text WebPart" 
            ExportMode="All" 
            />
        </zonetemplate>
    </asp:webpartzone>
    <br />
  </form>
</body>
</html>

在瀏覽器中載入網頁,然後在控制項的 WebPart 動詞功能表上,按一下匯出動詞,並遵循指示匯出包含控制項狀態和屬性資料的描述檔。

備註

根據預設, WebPart 控制項無法匯出,而且其 ExportMode 屬性會設定為 None 。 若要啟用匯出控制項的所有屬性,將ExportModeAll。 若要在防止匯出包含敏感性資料的屬性時只匯出特定屬性,請將 屬性值設定為 NonSensitiveData

若要匯出的屬性值描述WebPart控制項中,屬性也必須以標記Personalizable屬性的原始碼的中繼資料中的屬性。 如需詳細資訊,請參閱 PersonalizableAttribute

注意

若要為包含Web 組件控制項的 Web 應用程式啟用匯出功能,請在應用程式的Web.config檔案中,將 屬性新增至 <webParts> 區段內的 <system.web> 元素,如下列標記所示。

<webParts enableExport="true">

</webParts>

這個屬性無法由佈景主題或樣式表主題設定。 如需詳細資訊,請參閱 ThemeableAttributeASP.NET 主題和外觀

此屬性的個人化範圍設定為 Shared ,且只能由授權的使用者修改。 如需詳細資訊,請參閱 PersonalizableAttributeWeb 組件個人化概觀

適用於

另請參閱