ASP.NET HtmlImageControl


HTML Server ControlsHTML Server Controls

Definition and Usage

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


Properties

Attribute Description
Align How to arrange the image relative to surrounding elements. Legal values are:
  • top
  • middle
  • bottom
  • left
  • right
Alt A short description of the image.
Attributes Returns all attribute name and value pairs of this element.
Border The width of the border around the image.
Disabled A Boolean value indicating whether the control is disabled. The default is false.
Height The height of the image.
id The unique id of the control.
runat Specifies that this control is a server control. Must be set to "server".
Src The URL of the image to be displayed.
Style Sets or returns the CSS properties applied to this control.
TagName Returns the tag name of the element.
Visible A Boolean value indicating whether the control is visible.
Width The width of the image.


Examples

HTMLImage
In this example, we declare an HtmlImage control in a .aspx file (remember to nest the control inside an HtmlForm control). Then we modify the src, alt, and border attributes of the HtmlImage control in an event handler (an event handler is a subroutine that executes code for a given event). The Page_Load event is one of the many events that ASP.NET understands.

HTMLImage 2
In this example, we declare an HtmlImage control and an HTMLSelect control in a .aspx file (remember to nest the controls inside an HtmlForm control). Then we modify the src attribute of the HtmlImage control based on the user's selection. The selected value in the HTMLSelect control determines which image is displayed.


HTML Server ControlsHTML Server Controls Other Extensions