Prop Webcontrol Style Height
## ASP.NET WebControl Height Property
The `Height` property is a member of the `System.Web.UI.WebControls.Style` class. It is used to set or return the height of a Web server control.
---
## Definition and Usage
The `Height` property specifies the vertical dimension of a Web server control. This property is inherited by all standard Web server controls (such as `Button`, `Panel`, `TextBox`, etc.) from the base `WebControl` class.
---
## Syntax
### Declarative Syntax
```xml
```
### Property Values
| Value | Description |
| :--- | :--- |
| `value` | The height of the control. This must be a Unit value, typically expressed in pixels (e.g., `50px`) or as a percentage of the parent element's height (e.g., `50%`). |
---
## Code Examples
### Example 1: Setting Height Declaratively
The following example demonstrates how to set the height of an ASP.NET `Button` control to 50 pixels in the markup:
```xml
```
### Example 2: Setting Height Programmatically (C#)
You can also manipulate the `Height` property dynamically in your code-behind file using the `System.Web.UI.WebControls.Unit` structure:
```csharp
protected void Page_Load(object sender, EventArgs e)
{
// Set height using pixels
button1.Height = Unit.Pixel(50);
// Alternatively, set height using percentages
// button1.Height = Unit.Percentage(10);
}
```
---
## Considerations and Best Practices
1. **Unit Types**: The `Height` property accepts values of type `System.Web.UI.WebControls.Unit`. If you specify a raw number without a unit in the code-behind (e.g., `button1.Height = 50;`), ASP.NET implicitly converts it to pixels. However, it is best practice to explicitly use `Unit.Pixel()` or `Unit.Percentage()` for clarity.
2. **Browser Rendering**: ASP.NET renders the `Height` property as an inline CSS style attribute (`style="height: 50px;"`) in the output HTML.
3. **Container Constraints**: When using percentage-based heights (e.g., `100%`), ensure that the parent container has an explicitly defined height. Otherwise, the browser may render the control with a height of `auto` or collapse it.
YouTip