The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

WebPart.Height Property


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

Gets or sets the height of a zone.

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

public override Unit Height { get; set; }

Property Value

Type: System.Web.UI.WebControls.Unit

A Unit object that indicates the height of a WebPartZone. The default type of a Unit is pixels, as indicated by the Type property.

Internet Explorer rendering modes can affect the height of a WebPart control and the height of the zone that contains it. 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). For information about these modes, see the DHTML compatMode property.

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%">. 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.

When Internet Explorer is in standard mode, controls do not render to stretch to their full height in the following cases:

  • 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.

  • 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.

The following code example demonstrates the rendering issue that affects the height of WebPart controls in a WebPartZone. 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. The result is that in the WebPartZone, the shorter WebPart control does not stretch to the height of the zone upon rendering. 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" 

<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;

<html xmlns="" >
<head runat="server">
    <title>Untitled Page</title>
    <form id="form1" runat="server">
      <asp:webpartmanager id="wpmgr" runat="server" />
      <asp:webpartzone id="WebPartZone1" runat="server" 
          <asp:textbox id="TextBox1" runat="server" title="Text input">
          <asp:calendar id="Calendar1" runat="server" title="Personal Calendar" />
      <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" />

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:


Run the page, and now both WebPart controls stretch to fill the explicitly declared height of the zone.

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. 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. 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. Now remove the height attribute and run the page again. The controls now render relative to the height of the zone.

.NET Framework
Available since 2.0
Return to top