WebPart.Hidden 属性

定义

获取或设置一个值,该值指示是否在网页上显示 WebPart 控件。Gets or sets a value indicating whether a WebPart control is displayed on a Web page.

public:
 virtual property bool Hidden { bool get(); void set(bool value); };
[System.Web.UI.Themeable(false)]
[System.Web.UI.WebControls.WebParts.Personalizable]
public virtual bool Hidden { get; set; }
member this.Hidden : bool with get, set
Public Overridable Property Hidden As Boolean

属性值

如果在网页上显示 WebPart 控件,则为 false;否则为 truefalse if the WebPart control is displayed on a Web page; otherwise, true. 默认值为 falseThe default value is false.

属性

示例

下面的代码示例演示如何使用自定义 Web 部件控件的 Hidden 属性。The following code example demonstrates the use of the Hidden property for a custom Web Parts control. 本示例假定使用 WebPart 类概述的 "示例" 部分中的自定义控件 TextDisplayWebPartThis example assumes the use of a custom control, TextDisplayWebPart, which is found in the Example section of the WebPart class overview.

请注意,在网页的 <aspSample:TextDisplayWebPart> 元素的声明性标记中,Hidden 属性值设置为 "true"。Notice that in the Web page, in the declarative markup for the <aspSample:TextDisplayWebPart> element, the Hidden attribute value is set to true. 如果页面加载到浏览器中,则不会显示 TextDisplayWebPart 控件。The TextDisplayWebPart control will not appear if the page is loaded in a browser. 但是,该控件仍然存在于页面上和其区域中,如果你创建了这些连接,它仍可以与其他 WebPart 控件连接。However, the control is still present on the page and in its zone, and it still could participate in connections with other WebPart controls if you created those connections.

<%@ page language="C#" %>
<%@ register tagprefix="aspSample" 
             Namespace="Samples.AspNet.CS.Controls" 
             Assembly="TextDisplayWebPartCS"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <title>ASP.NET Example</title>
</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 Content WebPart" 
            Hidden="true" />
          </zonetemplate>
    </asp:webpartzone>
  </form>
</body>
</html>
<%@ page language="VB" %>
<%@ register tagprefix="aspSample" 
             Namespace="Samples.AspNet.VB.Controls" 
             Assembly="TextDisplayWebPartVB"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <title>ASP.NET Example</title>
</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 Content WebPart" 
            Hidden="true" />
          </zonetemplate>
    </asp:webpartzone>
  </form>
</body>
</html>

注解

隐藏的 WebPart 控件将保留在其区域中,实际上在其页面上呈现,并且参与到页面生命周期阶段(如 PreRender 阶段),尽管它在浏览器中不可见。A WebPart control that is hidden remains in its zone, is actually rendered on its page, and participates in page life cycle phases such as the PreRender phase, even though it is not visible in a browser. 这与 WebPart 关闭的控件不同,因为关闭的控件甚至不会呈现在页上,而隐藏控件在 Web 部件应用程序中呈现和活动,但用户不可见。This is different from WebPart controls that are closed, because closed controls are not even rendered on a page, while hidden controls are rendered and active in Web Parts applications, though not visible to users. Web 部件控件集通过将 WebPart 控件的级联样式表(CSS)样式设置为 display:none的值来隐藏该控件。The Web Parts control set hides the WebPart control by setting its cascading style sheet (CSS) style to a value of display:none.

即使控件的 Hidden 属性设置为 true,如果页面上的当前显示模式允许显示隐藏控件,仍然会显示该控件。Even if the Hidden property for a control is set to true, the control is still displayed if the current display mode on the page allows hidden controls to be displayed. 例如,编辑模式允许显示隐藏控件,以便用户可以对其进行编辑。For example, edit mode allows hidden controls to be displayed, so that users can edit them. 当隐藏控件在某些显示模式中可见时,控件的标题将显示一个字符串,指示控件处于隐藏状态。When hidden controls are visible in certain display modes, the title of the control displays a string indicating that the control is in hidden status.

WebPart 控件上的 Hidden 属性设置为 false(默认值)时,控件将显示在页面上。When the Hidden property on a WebPart control is set to false, which is the default, the control is displayed on the page. 请注意,如果 AllowHide 属性设置为 false,则不允许最终用户编辑 Hidden 属性值。Note that if the AllowHide property is set to false, end users are not allowed to edit the Hidden property value.

无法通过主题或样式表主题设置此属性。This property cannot be set by themes or style sheet themes. 有关详细信息,请参阅 ThemeableAttributeASP.NET 主题和外观For more information, see ThemeableAttribute and ASP.NET Themes and Skins.

适用于

另请参阅