Export (0) Print
Expand All
Expand Minimize

WebPartExportMode Enumeration

Note: This enumeration is new in the .NET Framework version 2.0.

Specifies whether all, some, or none of a WebPart control's properties can be exported.

Namespace: System.Web.UI.WebControls.WebParts
Assembly: System.Web (in system.web.dll)

public enum WebPartExportMode
public enum WebPartExportMode
public enum WebPartExportMode

 Member nameDescription
AllAll of a Web Parts control's properties can be exported. 
NoneNone of a Web Parts control's properties can be exported.  
NonSensitiveDataOnly properties of a Web Parts control that have been defined as non-sensitive can be exported.  

A value from the WebPartExportMode enumerator can be applied to the ExportMode property to specify which properties from a Web Parts control can be exported. By default, the properties of a WebPart control cannot be exported and the control's ExportMode property is set to None. To enable exporting all properties for the control, set the ExportMode value to All. To export only certain properties while preventing the export of properties that contain sensitive data, you set the property value to NonSensitiveData.

A property can be marked as sensitive through the PersonalizableAttribute attribute.

NoteNote

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>

The following code example demonstrates the use of the ExportMode property. Note that for the export code example to work, you must also update your Web.config file as indicated in the Remarks section.

The first part of this example contains the code for a control named TextDisplayWebPart. 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. 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. You can compile it explicitly and put the resulting assembly in your Web site's Bin folder or the global assembly cache. Alternatively, you can put the source code in your site's App_Code folder, where it will be dynamically compiled at run time. 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. For a walkthrough that demonstrates both methods of compiling, see Walkthrough: Developing and Using a Custom 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 (input.Text != String.Empty)
      {
        _contentText = input.Text + @"<br />";
        input.Text = String.Empty;
        DisplayContent.Text = this.ContentText;
      }
    }
  }
}

package Samples.AspNet.JSL.Controls; 

import System.*;
import System.Security.Permissions.*;
import System.Web.*;
import System.Web.UI.WebControls.*;
import System.Web.UI.WebControls.WebParts.*;

/** @attribute AspNetHostingPermission(SecurityAction.Demand, Level =
    AspNetHostingPermissionLevel.Minimal)
 */
/** @attribute AspNetHostingPermission(SecurityAction.InheritanceDemand, Level = 
    AspNetHostingPermissionLevel.Minimal)
 */
public class TextDisplayWebPart extends WebPart
{
    private String _contentText = null;
    private TextBox input;
    private Label displayContent;
    private String _subTitle = "Contoso, Ltd";

    public TextDisplayWebPart()
    {
        this.set_AllowClose(false);
    } //TextDisplayWebPart

    /** @attribute Personalizable(PersonalizationScope.User, true)
        @attribute WebBrowsable()
     */
    /** @property 
     */
    public String get_ContentText()
    {
        return _contentText;
    } //get_ContentText

    /** @property
     */
    public void set_ContentText(String value)
    {
        _contentText = value;
    } //set_ContentText

    protected void CreateChildControls()
    {
        get_Controls().Clear();
        displayContent = new Label();
        displayContent.set_BackColor(System.Drawing.Color.get_LightBlue());
        displayContent.set_Text(this.get_ContentText());
        this.get_Controls().Add(displayContent);
        input = new TextBox();
        this.get_Controls().Add(input);
        Button update = new Button();
        update.set_Text("Set Label Content");
        update.add_Click(new EventHandler(this.Submit_Click));
        this.get_Controls().Add(update);
        set_ChildControlsCreated(true);
    } //CreateChildControls

    private void Submit_Click(Object sender, EventArgs e)
    {
        // Update the label string.
        if (!(input.get_Text().Equals(""))) {
            _contentText = input.get_Text() + "<br />";
            input.set_Text("");
            displayContent.set_Text(this.get_ContentText());
        }
    } //Submit_Click
} //TextDisplayWebPart

The second part of the example shows how to reference the TextDisplayWebPart control in an ASP.NET Web page. 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"%>

<html>
<head id="Head1" runat="server">
  
</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="VJ#" %>
<%@ register tagprefix="aspSample" 
             Namespace="Samples.AspNet.JSL.Controls" 
             Assembly="TextDisplayWebPartJSL"%>

<html>
<head id="Head1" runat="server">
  
</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>

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.

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0

Community Additions

ADD
Show:
© 2014 Microsoft