YouTip LogoYouTip

Prop Webcontrol Checkbox Textalign

## ASP.NET Web Control: CheckBox TextAlign Property The `TextAlign` property is a key layout feature of the ASP.NET Web Server `CheckBox` control. This tutorial provides a comprehensive guide on how to use this property to align text relative to the checkbox element. --- ## Definition and Usage The `TextAlign` property is used to set or return the alignment of the text label associated with the `CheckBox` control. By default, the text label is displayed to the right of the checkbox element. However, you can change this behavior to position the text on the left side of the checkbox. ### Default Value * **"Right"**: The text label appears to the right of the checkbox. --- ## Syntax You can declare the `TextAlign` property inline within your `.aspx` markup or manipulate it programmatically in your code-behind file (C# or VB.NET). ### Declarative Syntax (ASPX Markup) ```asp ``` ### Property Values | Value | Description | | :--- | :--- | | `Left` | Aligns the text label to the left of the checkbox element. | | `Right` | Aligns the text label to the right of the checkbox element (Default). | --- ## Code Examples ### Example 1: Setting Alignment in ASPX Markup The following example demonstrates how to set the `TextAlign` property to `"Left"` directly in the markup. This places the label text before the checkbox. ```asp <%@ Page Language="C#" %> ASP.NET CheckBox TextAlign Example

CheckBox TextAlign Demonstration



``` ### Example 2: Setting Alignment Programmatically (Code-Behind) You can also dynamically change the alignment of the checkbox text at runtime using C#. ```csharp protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { // Programmatically set the text alignment to Left check1.TextAlign = TextAlign.Left; } } ``` --- ## Key Considerations 1. **Enum Type**: Programmatically, the `TextAlign` property accepts values from the `System.Web.UI.WebControls.TextAlign` enumeration (`TextAlign.Left` or `TextAlign.Right`). 2. **Accessibility and UX**: Left-aligned checkboxes are useful in specific form layouts, such as right-aligned form columns or mobile-optimized interfaces. Ensure your choice of alignment remains consistent across your application for a cohesive user experience. 3. **HTML Rendering**: When rendered in the browser, ASP.NET wraps the `CheckBox` in a `` element containing an `` and a `
← Prop Webcontrol Checkboxlist CProp Webcontrol Checkbox Text β†’