WebPart.Height 属性
定义
获取或设置区域的高度。Gets or sets the height of a zone.
public:
virtual property System::Web::UI::WebControls::Unit Height { System::Web::UI::WebControls::Unit get(); void set(System::Web::UI::WebControls::Unit value); };
[System.Web.UI.WebControls.WebParts.Personalizable]
public override System.Web.UI.WebControls.Unit Height { get; set; }
[<System.Web.UI.WebControls.WebParts.Personalizable>]
member this.Height : System.Web.UI.WebControls.Unit with get, set
Public Overrides Property Height As Unit
属性值
指示 Unit 的高度的 WebPartZone 对象。A Unit object that indicates the height of a WebPartZone. 按照 Unit 属性的指示,Type 的默认类型是像素。The default type of a Unit is pixels, as indicated by the Type property.
- 属性
示例
下面的代码示例演示了影响中的控件高度的呈现问题 WebPart WebPartZone 。The following code example demonstrates the rendering issue that affects the height of WebPart controls in a WebPartZone. 若要演示此问题,必须在 Internet Explorer 中运行此页面。To demonstrate this issue, you must run the page in Internet Explorer.
请注意,区域的方向设置为水平,而区域的高度和其中的控件未显式设置。Note that the zone's orientation is set to horizontal, and that the height of the zone and the controls within it is not set explicitly. 结果是,在中 WebPartZone ,较短的 WebPart 控件在呈现时不会延伸到区域的高度。The result is that in the WebPartZone, the shorter WebPart control does not stretch to the height of the zone upon rendering. 但是,如果 DOCTYPE 从页中删除声明并再次运行该页,则不会发生此问题,因为现在浏览器将不会在标准模式下呈现页。However, if you remove the DOCTYPE declaration from the page and run the page again, the issue does not occur, because now the browser will not render the page in standards mode.
<%@ Page Language="C#"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
protected void Button1_Click(object sender, EventArgs e)
{
wpmgr.DisplayMode = WebPartManager.DesignDisplayMode;
}
protected void Button2_Click(object sender, EventArgs e)
{
wpmgr.DisplayMode = WebPartManager.BrowseDisplayMode;
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<asp:webpartmanager id="wpmgr" runat="server" />
<asp:webpartzone id="WebPartZone1" runat="server"
layoutorientation="horizontal">
<zonetemplate>
<asp:textbox id="TextBox1" runat="server" title="Text input">
</asp:textbox>
<asp:calendar id="Calendar1" runat="server" title="Personal Calendar" />
</zonetemplate>
</asp:webpartzone>
<asp:button id="Button1" runat="server" text="Design Mode"
onclick="Button1_Click" />
<br />
<asp:button id="Button2" runat="server" onclick="Button2_Click"
text="Browse Mode" />
</form>
</body>
</html>
<%@ Page Language="VB"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
Protected Sub Button1_Click(ByVal sender As Object, _
ByVal e As System.EventArgs)
wpmgr.DisplayMode = WebPartManager.DesignDisplayMode
End Sub
Protected Sub Button2_Click(ByVal sender As Object, _
ByVal e As System.EventArgs)
wpmgr.DisplayMode = WebPartManager.BrowseDisplayMode
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<asp:webpartmanager id="wpmgr" runat="server" />
<asp:webpartzone id="WebPartZone1" runat="server"
layoutorientation="horizontal">
<zonetemplate>
<asp:textbox id="TextBox1" runat="server" title="Text input">
</asp:textbox>
<asp:calendar id="Calendar1" runat="server" title="Personal Calendar" />
</zonetemplate>
</asp:webpartzone>
<asp:button id="Button1" runat="server" text="Design Mode"
onclick="Button1_Click" />
<br />
<asp:button id="Button2" runat="server" onclick="Button2_Click"
text="Browse Mode" />
</form>
</body>
</html>
若要查看 "备注" 部分中介绍的解决方法 () 的工作方式,请尝试将 height 属性添加到 <asp:webpartzone> 元素,同时在 DOCTYPE 页面中保留声明。To see how the workaround (described in the Remarks section) works, try adding a height attribute to the <asp:webpartzone> element, while keeping the DOCTYPE declaration in the page. 你可以使用以下代码将该属性添加到标记:You can use the following code to add the attribute to the tag:
Height="200px"
运行页,现在这两个 WebPart 控件都将拉伸以填充区域的显式声明高度。Run the page, and now both WebPart controls stretch to fill the explicitly declared height of the zone.
你还可以尝试此代码示例,以在另一种情况下(当区域的设置为时,将出现与高度相关的呈现问题 LayoutOrientation Vertical 。You can also experiment with this code example to observe the height-related rendering issue in the other scenario, which occurs when the zone's LayoutOrientation is set to Vertical. LayoutOrientation从元素中删除现有属性及其值 <asp:webpartzone> ,这将导致区域的方向恢复为默认垂直方向。Remove the existing LayoutOrientation attribute and its value from the <asp:webpartzone> element, which will cause the zone's orientation to revert to the default vertical orientation. <asp:webpartzone>如上文所述,将元素的高度特性设置为200像素,并运行页。Set the height attribute on the <asp:webpartzone> element to 200 pixels, as you did above, and run the page. 区域的高度看起来太大,控件不会按区域的高度调整大小。The zone's height looks too large, and the controls are not sized proportionately to the zone's height. 现在删除 height 属性,然后再次运行页面。Now remove the height attribute and run the page again. 控件现在相对于区域的高度进行呈现。The controls now render relative to the height of the zone.
注解
Internet Explorer 呈现模式可能会影响控件的高度 WebPart 以及包含它的区域的高度。Internet Explorer rendering modes can affect the height of a WebPart control and the height of the zone that contains it. Internet Explorer 将在兼容模式下呈现网页 (与以前的浏览器版本) 或标准模式下的向后兼容, (在 DOCTYPE 页) 中是否存在声明来确定。Internet Explorer renders Web pages either in compatibility mode (backward compatible with previous browser versions) or in standards mode (determined by the presence of a DOCTYPE declaration in the page). 有关这些模式的信息,请参阅 DHTML document.compatmode 属性。For information about these modes, see the DHTML compatMode property.
如果 Internet Explorer 在标准模式下呈现页面,则在某些情况下,它可能不会在表中调整单元格的大小,即使单元格的 HTML 标记为时也是如此 <td height="100%"> 。When Internet Explorer renders a page in standards mode, under some circumstances it might not resize cells in tables, even when a cell's HTML markup is <td height="100%">. 因此, WebPart 将呈现控件及其包含区域,以便控件不会延伸到区域的全部高度。As a result, WebPart controls and their containing zone are rendered so that the controls do not stretch to the full height of the zone.
当 Internet Explorer 处于 "标准" 模式下时,在以下情况下,控件不会呈现为高度拉伸:When Internet Explorer is in standard mode, controls do not render to stretch to their full height in the following cases:
当区域的 LayoutOrientation 属性设置为 Vertical ,并且在区域上显式设置了高度时,为。When a zone's LayoutOrientation property is set to Vertical and you explicitly set the height on the zone. 若要使控件能够填充区域的全部高度,请不要指定水平方向区域的高度。To enable controls to fill the full height of the zone, do not specify the height of a horizontally oriented zone.
当区域的 LayoutOrientation 属性设置为 Horizontal ,并且您没有显式设置区域或所包含控件的高度。When a zone's LayoutOrientation property is set to Horizontal and you do not explicitly set the height of the zone or of the contained controls. 若要使控件能够填充区域的全部高度,请设置区域的高度或垂直方向区域中控件的高度。To enable controls to fill the full height of the zone, set the height of the zone or of the controls in a vertically oriented zone.