YouTip LogoYouTip

Prop Webcontrol Standard

## ASP.NET Web Control Standard Properties In ASP.NET, Web Server Controls (such as ``, ``, or ``) inherit from the base `System.Web.UI.WebControls.WebControl` class. This class provides a common set of properties that control the appearance, behavior, and styling of almost all Web Server Controls. Understanding these standard properties allows you to programmatically customize and style your user interface elements consistently. --- ## Standard Properties Reference The following table lists the standard properties inherited from the `WebControl` class, along with their descriptions and the minimum .NET Framework version required. | Property | Description | .NET Version | | :--- | :--- | :--- | | **AccessKey** | Specifies a keyboard shortcut key to quickly navigate to the control. | 1.0 | | **Attributes** | Gets the collection of arbitrary attributes (not represented by properties) applied to the control. | 1.0 | | **BackColor** | Gets or sets the background color of the Web server control. | 1.0 | | **BorderColor** | Gets or sets the border color of the Web server control. | 1.0 | | **BorderStyle** | Gets or sets the border style (e.g., Solid, Dashed, Double) of the Web server control. | 1.0 | | **BorderWidth** | Gets or sets the border width of the Web server control. | 1.0 | | **CssClass** | Gets or sets the CSS class rendered by the Web server control on the client. | 1.0 | | **Enabled** | Gets or sets a value indicating whether the Web server control is enabled and can respond to user interaction. | 1.0 | | **Font** | Gets the font properties (such as Bold, Italic, Name, Size) associated with the Web server control. | 1.0 | | **EnableTheming** | Gets or sets a value indicating whether themes are enabled for this control. | 2.0 | | **ForeColor** | Gets or sets the foreground color (typically the text color) of the Web server control. | 1.0 | | **Height** | Gets or sets the height of the Web server control. | 1.0 | | **IsEnabled** | Gets a value indicating whether the control is enabled (read-only helper property). | 2.0 | | **SkinID** | Gets or sets the skin to apply to the control. | 2.0 | | **Style** | Gets a collection of inline CSS style attributes that are applied to the control. | 1.0 | | **TabIndex** | Gets or sets the tab order of the Web server control. | 1.0 | | **ToolTip** | Gets or sets the text displayed when the mouse pointer hovers over the Web server control. | 1.0 | | **Width** | Gets or sets the width of the Web server control. | 1.0 | --- ## Syntax and Usage You can set these standard properties in two ways: **declaratively** in your `.aspx` markup, or **programmatically** in your code-behind file (C# or VB.NET). ### 1. Declarative Markup (.aspx) ```html ``` ### 2. Programmatic Code-Behind (C#) ```csharp protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { // Set styling properties programmatically txtUsername.BackColor = System.Drawing.Color.LightYellow; txtUsername.ForeColor = System.Drawing.Color.DarkBlue; txtUsername.BorderColor = System.Drawing.Color.Blue; txtUsername.BorderStyle = BorderStyle.Solid; txtUsername.BorderWidth = Unit.Pixel(2); // Set accessibility and behavior properties txtUsername.ToolTip = "Enter your username here"; txtUsername.TabIndex = 1; txtUsername.AccessKey = "U"; } } ``` --- ## Code Examples ### Example 1: Styling a Button Dynamically This example demonstrates how to change the visual properties of an ASP.NET Button control dynamically when a user interacts with the page. **Markup (`Default.aspx`):** ```html ``` **Code-Behind (`Default.aspx.cs`):** ```csharp using System; using System.Web.UI.WebControls; public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { // Set initial properties on first load if (!IsPostBack) { btnSubmit.ToolTip = "Click to submit your data"; btnSubmit.Font.Bold = true; btnSubmit.Font.Size = FontUnit.Medium; } } protected void btnSubmit_Click(object sender, EventArgs e) { // Disable the button and change its appearance after submission btnSubmit.Enabled = false; btnSubmit.Text = "Processing..."; btnSubmit.BackColor = System.Drawing.Color.LightGray; btnSubmit.ForeColor = System.Drawing.Color.DarkGray; btnSubmit.BorderColor = System.Drawing.Color.Gray; } } ``` --- ## Considerations and Best Practices 1. **CSS vs. Inline Properties:** While properties like `BackColor`, `ForeColor`, and `Font` are convenient for quick prototyping, it is highly recommended to use the `CssClass` property in production environments. This keeps your presentation layer (CSS) separated from your application logic. 2. **Unit Measurements:** Properties like `Height` and `Width` accept a `Unit` structure. You can define them in pixels (`Unit.Pixel(100)`) or percentages (`Unit.Percentage(50)`). 3. **Accessibility (A11y):** Always make use of the `AccessKey`, `TabIndex`, and `ToolTip` properties to ensure your web application is accessible to users navigating via keyboard or screen readers.
← Prop Control StandardPython Multithreading β†’