AllowHide Property

WebPart.AllowHide Property


Gets or sets a value indicating whether end users are allowed to hide a WebPart control.

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

public virtual bool AllowHide { get; set; }

Property Value

Type: System.Boolean

true if the WebPart control can be hidden; otherwise, false. The default value is true.

The AllowHide property determines whether users can modify the Hidden property. In the default case, when the property value is true, users can change the value when the control is being edited. By default, controls are not hidden and their Hidden property value is false. When a WebPart control is being edited, if a user selects a check box to hide the control (which sets the Hidden property to true), the control will no longer be visible when the page returns to browse mode.

Hidden controls are distinct from controls that are closed, because the Hidden property has a distinct meaning within the Web Parts control set. Closed controls are not even rendered on a page, and do not participate in page life cycle events. In contrast, while hidden WebPart controls are not visible to users, they are still rendered on a Web page, are still contained in a zone, and can still maintain connections with other WebPart controls as part of a Web Parts application.

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 AllowHide property for a custom Web Parts control, so that the custom control cannot be hidden by a user. This example assumes the use of a custom WebPart control, TextDisplayWebPart, which is found in the Example section of the WebPart class overview.

The code example also uses a custom user control that enables users to change display modes on a Web Parts page. The user control is referenced by means of a Register directive near the top of the Web page that hosts the user control. For a detailed description of how to create this user control and work with display modes, see Walkthrough: Developing and Using a Custom Web Server Control.

In the declarative markup for the Web page, on the <aspSample:TextDisplayWebPart> element that references the control, note the AllowHide="false" attribute, which prevents a user who is editing the control from being able to hide it. Load the page in a browser and use the Display Mode drop-down list control to change the display mode to edit mode. Next, click the verbs menu in the title bar of the WebPart control and click the edit verb. As the edit user interface (UI) is displayed, you can see that the UI to edit the Hidden property is now disabled, which occurred because you set the AllowHide property value to false.

.NET Framework
Available since 2.0
Return to top
© 2015 Microsoft