ASP.NET HtmlImage Control

Definition and Usage

The HtmlImage control is used to control the <img> element. In HTML, the <img> element is used to display images.

Property

Property Description
Align

How to align the image around the surrounding elements. Valid values include:

  • top
  • middle
  • bottom
  • left
  • right
Alt A brief description of the image.
Attributes Returns all attribute names and value pairs of the element.
Border Width of the border around the image.
Disabled A boolean value indicating whether the control is disabled. The default is false.
Height Height of the image.
id The unique id of the control.
runat Specifies that the control is a server control. It must be set to "server".
Src The URL of the image to be displayed.
Style Sets or returns the CSS properties applied to the control.
TagName Returns the tag name of the element.
Visible A boolean value indicating whether the control is visible.
Width Width of the image.

Example

HTMLImage
In this example, we declare an HtmlImage control in the .aspx file. Then we modify the src, alt, and border properties of this HtmlImage control in an event handler. The Page_Load event is one of the many events understood by ASP.NET.
HTMLImage 2
In this example, we declare an HtmlImage control and an HTMLSelect control in the .aspx file. Then we will modify the src attribute of the HtmlImage control based on the user's selection. The selected value in the HtmlSelect control determines which image to display.