Prop Webcontrol Hyperlink Imageurl
## ASP.NET HyperLink ImageUrl Property
The `ImageUrl` property is a key feature of the ASP.NET Web Server `HyperLink` control. It allows developers to display an image that functions as a clickable hyperlink instead of standard text.
---
## Definition and Usage
The `ImageUrl` property is used to set or return the URL of the image that will be displayed as the hyperlink.
When the `ImageUrl` property is set, the `HyperLink` control renders as an `` tag containing an `
` tag. If the image is unavailable or cannot be loaded, the browser will display the text specified in the `Text` property as fallback alternative text (the `alt` attribute of the image).
---
## Syntax
```xml
```
### Property Values
| Property Value | Description |
| :--- | :--- |
| `URL` | The path/URL of the image to be displayed. This can be a relative path (e.g., `images/logo.png`), an absolute path, or an application-relative path using the tilde operator (e.g., `~/images/logo.png`). |
---
## Code Examples
### Example 1: Basic Declarative Implementation
The following example demonstrates how to set the `ImageUrl` property declaratively in your `.aspx` markup.
```xml
```
### Example 2: Programmatic Implementation (Code-Behind)
You can also set or modify the `ImageUrl` dynamically in your C# code-behind file.
**ASPX Markup:**
```xml
```
**C# Code-Behind:**
```csharp
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
dynamicLink.NavigateUrl = "https://www.youtip.co";
dynamicLink.ImageUrl = "~/images/dynamic-banner.png";
dynamicLink.Text = "Go to YouTip Homepage"; // Fallback alt text
}
}
```
---
## Key Considerations
1. **Fallback Text (`Text` Property):** Always define the `Text` property alongside `ImageUrl`. The `Text` value is rendered as the `alt` attribute of the generated image, which is crucial for web accessibility (screen readers) and SEO.
2. **Path Resolution:**
* Using relative paths like `images/pic.png` works well if the page structure remains constant.
* Using the application-relative path syntax `~/images/pic.png` is highly recommended in ASP.NET, as it automatically resolves the correct path regardless of the folder depth of the current page.
3. **Precedence:** If both the `ImageUrl` and `Text` properties are set, the image takes visual precedence. The text will only be visible if the image fails to load.
YouTip