WebPart.ExportMode 属性

定义

获取或设置是否可以导出所有、某些 WebPart 控件属性或不能导出该控件的任何属性。Gets or sets whether all, some, or none of a WebPart control's properties can be exported.

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; }
member this.ExportMode : System.Web.UI.WebControls.WebParts.WebPartExportMode with get, set
Public Overridable Property ExportMode As WebPartExportMode

属性值

WebPartExportMode 值之一。One of the WebPartExportMode values. 默认值为 NoneThe default is None.

属性

例外

指定的值不是 WebPartExportMode 值之一。The value specified is not one of the WebPartExportMode values.

该控件已加载,控件的个性化范围已设置为 User 范围。The control is already loaded and the personalization scope of the control is set to the User scope.

示例

下面的代码示例演示如何使用 ExportMode 属性。The following code example demonstrates the use of the ExportMode property. 请注意,若要使导出代码示例正常运行,还必须通过将属性 enableExport="true" 添加到 <webParts> 元素来更新 Web.config 文件,如 "备注" 部分所示。Note that for the export code example to work, you must also update your Web.config file by adding the attribute enableExport="true" to the <webParts> element, as indicated in the Remarks section.

此示例的第一部分包含名为 TextDisplayWebPart的控件的代码。The first part of this example contains the code for a control named TextDisplayWebPart. 此控件与在 WebPart 类概述的 "示例" 部分中找到的自定义控件相同,不同之处在于它将 Personalizable 特性添加到 TextDisplayWebPart.ContentText 属性,以便可以导出属性。This control is the same as the custom control that is found in the Example section of the WebPart class overview, except that it adds a Personalizable attribute to the TextDisplayWebPart.ContentText property so the property can be exported. 请注意,属性声明包括 isSensitive 参数 true 的值,这意味着该属性将被标记为敏感数据以供导出。Note that the attribute declaration includes a value of true for the isSensitive parameter, meaning that the property is marked as sensitive data for export purposes. 要使代码示例运行,必须编译此源代码。For the code example to run, you must compile this source code. 可以显式编译该程序集,并将生成的程序集放在网站的 Bin 文件夹或全局程序集缓存中。You can compile it explicitly and put the resulting assembly in your Web site's Bin folder or the global assembly cache. 或者,您可以将源代码放在站点的 App_Code 文件夹中,它将在运行时动态编译。Alternatively, you can put the source code in your site's App_Code folder, where it will be dynamically compiled at run time. 此代码示例假定您将源代码编译成一个程序集,将其放在您的 Web 应用程序的 Bin 子文件夹中,并在您的网页中使用 Register 指令引用该程序集。This code example assumes that you compile the source code into an assembly, place it in a Bin subfolder of your Web application, and reference the assembly with a Register directive in your Web page. 有关演示两种编译方法的演练,请参阅演练:开发和使用自定义 Web 服务器控件For a walkthrough that demonstrates both methods of compiling, see Walkthrough: Developing and Using a Custom Web Server Control.

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 

该示例的第二部分演示如何在 ASP.NET 网页中引用 TextDisplayWebPart 控件。The second part of the example shows how to reference the TextDisplayWebPart control in an ASP.NET Web page. 请注意,在声明性标记中,ExportMode 属性值设置为 All,这意味着甚至将导出具有敏感值的属性。Note that in the declarative markup, the ExportMode property value is set to All, meaning that even properties with sensitive values will be exported.

<%@ 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 控件的谓词菜单上,单击 "导出" 谓词,然后按照说明导出包含控件状态和属性数据的描述文件。Load the Web page in a browser, and on the verbs menu of the WebPart control, click the export verb and follow the instructions to export a description file containing the control's state and property data.

注解

默认情况下,不能导出 WebPart 控件并且其 ExportMode 属性设置为 NoneBy default, a WebPart control cannot be exported and its ExportMode property is set to None. 若要导出控件的所有属性,请将 ExportMode 值设置为 AllTo enable exporting all properties for the control, set the ExportMode value to All. 若要仅导出某些属性,同时禁止导出包含敏感数据的属性,请将属性值设置为 NonSensitiveDataTo export only certain properties while preventing the export of properties that contain sensitive data, you set the property value to NonSensitiveData.

若要导出 WebPart 控件的属性值说明,还必须使用属性的源代码的元数据中的 Personalizable 特性标记属性。To export property value descriptions for a WebPart control, the properties must also be marked with the Personalizable attribute in the metadata for the property's source code. 有关详细信息,请参阅 PersonalizableAttributeFor details, see PersonalizableAttribute.

备注

若要为包含 Web 部件控件的 Web 应用程序启用导出功能,请在应用程序的 web.config 文件中将特性添加到 <system.web> 节中的 <webParts> 元素,如以下标记所示。To enable the export feature for a Web application that includes Web Parts controls, in the Web.config file for your application, you must add an attribute to the <webParts> element within the <system.web> section, as in the following markup.

<webParts enableExport="true">

</webParts>

无法通过主题或样式表主题设置此属性。This property cannot be set by themes or style sheet themes. 有关详细信息,请参阅 ThemeableAttributeASP.NET 主题和外观For more information, see ThemeableAttribute and ASP.NET Themes and Skins.

此属性的个性化设置范围设置为 Shared,只能由授权用户修改。The personalization scope of this property is set to Shared and can be modified only by authorized users. 有关详细信息,请参阅 PersonalizableAttributeWeb 部件个性化概述For more information, see PersonalizableAttribute and Web Parts Personalization Overview.

适用于

另请参阅