WebPartExportMode 枚举

定义

指定 WebPart 控件的属性是可以全部导出、部分导出还是无法导出。

public enum class WebPartExportMode
public enum WebPartExportMode
type WebPartExportMode = 
Public Enum WebPartExportMode
继承
WebPartExportMode

字段

All 1

Web 部件控件的所有属性都可以导出。

None 0

无法导出 Web 部件控件的任何属性。

NonSensitiveData 2

仅能导出 Web 部件控件的已定义为非敏感数据的属性。

示例

以下示例演示了 WebPart.ExportMode 该属性的使用。 请注意,若要使导出代码示例正常工作,还必须更新Web.config文件,如 “备注 ”部分所示。

The first part of this example contains the code for a control named TextDisplayWebPart. 此控件与类的“示例”部分中找到的WebPart自定义控件相同,只不过它向TextDisplayWebPart.ContentText属性添加一个PersonalizableAttribute控件,以便导出该属性。 请注意,属性声明包含参数的值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 属性值设置为“全部”,这意味着即使具有敏感值的属性也会导出。

<%@ 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>

在浏览器中加载网页,然后在控件的 ExportMode 谓词菜单上,单击导出谓词,并按照说明导出包含控件的状态和属性数据的说明文件。

注解

枚举中的WebPartExportMode值可以应用于WebPart.ExportMode属性,以指定可从Web 部件控件导出哪些属性。 默认情况下,无法导出控件的属性 WebPart ,并且控件 ExportMode 的属性设置为 None。 若要启用导出控件的所有属性,请将 ExportMode 值设置为 All。 若要仅导出某些属性,同时阻止导出包含敏感数据的属性,请将属性值设置为 NonSensitiveData

可以通过属性将属性标记为敏感 PersonalizableAttribute

备注

若要为包含Web 部件控件的 Web 应用程序启用导出功能,必须在应用程序的Web.config文件中向节中的<system.web>元素添加属性<webParts>,如以下标记所示:

<webParts enableExport="true">
</webParts>

适用于

另请参阅