Share via


How to: Export Web Parts Control Settings

Part of the functionality of the Web Parts control set is the ability to import custom Web Parts controls through the use of the ImportCatalogPart control. However, before a control can be imported by an end user it must be made available for export by the page developer.

After you have completed the export operation, you will need a way for users to import the control. For more information, see How to: Enable Users to Import Web Parts Control Settings.

To enable a custom Web Parts control for export

  1. Create an ASP.NET page that contains a custom Web Parts control.

    This control can be derived from the WebPart class or be any inherited control or user control placed inside a WebPartZone zone. For more information about how to create a Web Parts page, see Walkthrough: Creating a Web Parts Page. For an example of a custom Web Parts control, see WebPart.

    Note

    Only properties with the Personalizable attribute are included in the .WebPart file used for export.

  2. In your Web.config file, inside the <system.web> section, add a <webParts> element with enableExport set to true, as shown in the following example.

    <webParts enableExport="true"></webParts>
    
  3. Set the ExportMode property of the control to all. If your control is derived from WebPart, you can do this in markup as shown in the following example.

    <aspSample:CustomWebPart id="Sample" runat="server" ExportMode="All" />
    

    If you are not using an inheritedWebPart control but are using another control inside a WebPartZone zone, you must set the ExportMode property of the containing GenericWebPart control in code, as in the example shown in the Example section.

  4. 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 that contains the control's state and property data.

Example

To export a control that does not inherit from the WebPart class, you must first place the control inside a WebPartZone zone on the page. This automatically wraps the control in a GenericWebPart control, which you can access through code to set the ExportMode property during the Page_Load event. In the following example, Control1 is the name of the control to export.

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    Dim gwp As GenericWebPart
    gwp = Control1.Parent
    gwp.ExportMode = WebPartExportMode.All
End Sub
protected void Page_Load(object sender, EventArgs e)
{
    GenericWebPart gwp = (GenericWebPart) Control1.Parent;
    gwp.ExportMode = WebPartExportMode.All;
} 

See Also

Tasks

How to: Treat a User Control as a Web Parts Control

How to: Enable Users to Import Web Parts Control Settings

How to: Enable Users to Import Web Parts Control Settings

Reference

System.Web.UI.WebControls.WebParts

WebPart

GenericWebPart

ExportMode

ImportCatalogPart

Other Resources

ASP.NET Web Parts Controls