WebPart::AllowClose Property


The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

Gets or sets a value indicating whether an end user can close a WebPart control on a Web page.

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

property bool AllowClose {
	virtual bool get();
	virtual void set(bool value);

Property Value

Type: System::Boolean

true if the control can be closed on a Web page; otherwise, false. The default value is true.

After a user closes a WebPart control on a Web page, the control is no longer visible or available on the page. The closed control is added to the page catalog, a Web Parts entity that stores a reference to the control. If a developer adds a PageCatalogPart control to the page within a CatalogZone control, users are able to switch the page to catalog display mode, select the closed control in the page catalog, and add it back to the page.


A closed WebPart control can be added back to a page either programmatically, or by a user who selects the closed control from the page catalog when the page is in catalog display mode.

Closing a WebPart control is different from deleting it. A closed control can be added back to a page, while a deleted control is permanently removed. For more information on deleting controls, see the DeleteWebPart method. Closing a control is also different from hiding it. A control that is hidden is still present on the page, still participates in page life cycle events, and is only hidden from the user's view, but a closed control is not even rendered on a page.

Both static and dynamic WebPart controls (static controls are declared in a page's markup, while dynamic controls are added programmatically) can be closed.

If a developer sets the AllowClose property to false, a close verb does not appear on the control, and the user is not able to close the control.

This property cannot be set by themes or style sheet themes. For more information, see ThemeableAttribute and ASP.NET Themes and Skins.

The personalization scope of this property is set to Shared and can be modified only by authorized users. For more information, see PersonalizableAttribute and Web Parts Personalization Overview.

The following code example demonstrates how to change the default setting of the AllowClose property for a custom WebPart control, so that it cannot be closed.

The first part of this example contains the code for a custom WebPart control named TextDisplayWebPart. Note that in the constructor of the custom control, the TextDisplayWebPart.AllowClose property is set to false, which has the effect of preventing users from closing the control on a Web page. This means that the close verb on the verbs menu of the control will be disabled for users. 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 Web Server Control.

No code example is currently available or this language may not be supported.

The second part of the example shows how to reference the TextDisplayWebPart control in an ASP.NET Web page. Note that in the <aspSample:TextDisplayWebPart> element that references the control, you could also change the value of the property set by the control's constructor. To allow the control to be closed, simply add an AllowClose="true" attribute to the element in the declarative markup.

No code example is currently available or this language may not be supported.

.NET Framework
Available since 2.0
Return to top