YouTip LogoYouTip

Prop Webcontrol Image Alternatetext

## ASP.NET Image AlternateText Property The `AlternateText` property is a key attribute of the ASP.NET Web Server `Image` control. It is used to specify or retrieve the alternative text displayed in place of an image when the image file is unavailable, cannot be loaded, or for accessibility purposes. --- ## Definition and Usage The `AlternateText` property serves two primary purposes: 1. **Fallback Text:** It specifies the text to display if the image specified by the `ImageUrl` property is missing, broken, or cannot be loaded by the browser. 2. **Accessibility (SEO & Screen Readers):** It provides a textual description of the image for visually impaired users utilizing screen readers. In HTML, this property renders directly as the `alt` attribute of the `` tag. > **Note:** In some older browsers (such as legacy versions of Internet Explorer), this alternative text may also appear as a tooltip when a user hovers their mouse pointer over the image. For modern, cross-browser tooltips, you should use the `ToolTip` property instead. --- ## Syntax ```xml ``` ### Property Values | Attribute Value | Description | | :--- | :--- | | `text` | A string value that defines the alternative text for the image. | --- ## Code Example The following example demonstrates how to set the `AlternateText` property on an `Image` control. In this scenario, the image file `missing_img.gif` does not exist, forcing the browser to display the fallback alternative text. ```xml
``` When rendered to the browser, the control generates the following standard HTML output: ```html Image Text ``` --- ## Best Practices and Considerations * **Always Provide Alt Text:** For web accessibility compliance (such as WCAG and Section 508), always populate the `AlternateText` property. * **Decorative Images:** If the image is purely decorative and does not add informational value to the page, you can set `AlternateText=""` (an empty string). This signals to screen readers to skip the image. * **Tooltips vs. Alt Text:** Do not rely on `AlternateText` to display hover tooltips. If you want a consistent tooltip across all modern browsers, use the `ToolTip` property of the `Image` control (which renders as the HTML `title` attribute).
← Prop Webcontrol Image ImagealiProp Webcontrol Hyperlink Imag β†’