Gets or sets a value indicating whether an end user can close a WebPart control on a Web page.
Assembly: System.Web (in System.Web.dll)
[<PersonalizableAttribute(PersonalizationScope.Shared)>] [<ThemeableAttribute(false)>] abstract AllowClose : bool with get, set [<PersonalizableAttribute(PersonalizationScope.Shared)>] [<ThemeableAttribute(false)>] override AllowClose : bool with get, set
Property ValueType: 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 property to false, a close verb does not appear on the control, and the user is not able to close the control.
The following code example demonstrates how to change the default setting of the 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.
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.