Prop Webcontrol Style Borderwidth
## ASP.NET WebControl BorderWidth Property
The `BorderWidth` property is a member of the `System.Web.UI.WebControls.Style` class. It is used to get or set the width of the border for a Web server control.
---
## Definition and Usage
The `BorderWidth` property defines the thickness of the border surrounding a Web control. This property is rendered as the CSS `border-width` property on the client side.
When setting this property, you must specify a value that includes a valid unit of measurement (such as pixels, points, or inches). If you specify a numeric value without a unit, the system defaults to pixels (`px`).
---
## Syntax
### Declarative Syntax
```xml
```
### Property Values
| Value | Description |
| :--- | :--- |
| `length` | The width of the border. This must be a valid .NET Unit measurement. Valid units include: `px` (pixels), `pt` (points), `pc` (picas), `in` (inches), `mm` (millimeters), or `cm` (centimeters). |
---
## Code Examples
### Example 1: Setting BorderWidth on a Table Control (Declarative)
The following example demonstrates how to set the border width of an `asp:Table` control to `5px` using declarative markup.
```xml
```
### Example 2: Setting BorderWidth Dynamically (C# / Code-Behind)
You can also manipulate the `BorderWidth` property programmatically in your code-behind file using the `Unit` structure.
```csharp
// Setting the border width of a Button control to 3 pixels
Button1.BorderWidth = Unit.Pixel(3);
// Setting the border width using a percentage or other units
Button1.BorderWidth = Unit.Parse("0.5in");
```
---
## Technical Considerations
1. **Dependency on BorderStyle**: For the `BorderWidth` to be visible on the webpage, you must also set the `BorderStyle` property (e.g., `Solid`, `Double`, `Dashed`). If `BorderStyle` is set to `NotSet` or `None`, the border will not be displayed regardless of the `BorderWidth` value.
2. **Browser Rendering**: ASP.NET translates the `BorderWidth` property into inline CSS (`border-width: 5px;`) when rendering the HTML element. Ensure the target client browsers support the specified units.
3. **Negative Values**: Negative values for the border width are not allowed and will throw an `ArgumentOutOfRangeException`.
YouTip