Prop Webcontrol Button Text
## ASP.NET Web Control: Button Text Property
The `Text` property is a fundamental property of the ASP.NET Web Control `Button`. It is used to get or set the text caption displayed on the button control.
---
## Definition and Usage
The `Text` property defines the label or text that appears on the face of the `Button` control. This is the primary text that users see and interact with (e.g., "Submit", "Cancel", "Save").
By default, this property is empty. You can set it statically in the markup or dynamically in the code-behind file (C# or VB.NET) during runtime.
---
## Syntax
### Declarative Syntax (ASPX Markup)
```html
```
### Property Values
| Property | Type | Description |
| :--- | :--- | :--- |
| **Text** | `String` | Specifies the text caption displayed on the Button control. The default value is an empty string (`""`). |
---
## Code Examples
### Example 1: Basic Declarative Usage
The following example demonstrates how to set the `Text` property of a `Button` control directly in the `.aspx` markup.
```html
```
### Example 2: Dynamic Text Modification (Code-Behind)
You can also change the button's text dynamically at runtime based on user interaction or application state.
**ASPX Markup:**
```html
```
**C# Code-Behind:**
```csharp
protected void btnAction_Click(object sender, EventArgs e)
{
// Change the button text after it is clicked
btnAction.Text = "Processing...";
}
```
---
## Key Considerations
1. **HTML Encoding:** The value of the `Text` property is automatically HTML-encoded by ASP.NET before rendering. This prevents Cross-Site Scripting (XSS) vulnerabilities if you are displaying user-submitted data on the button.
2. **Localization:** For multi-lingual applications, the `Text` property can be bound to local resource files (`.resx`) using the `<%$ Resources: ... %>` expression syntax.
3. **CSS Styling:** The text inside the button inherits styles from the button's CSS class or inline styles (such as `Font-Bold`, `ForeColor`, etc.).
YouTip