asp.net.ph

Skip Navigation LinksHome > Getting Started > ASP.NET Syntax > ASP.NET Syntax for HTML Controls > HtmlImage

HtmlImage Control Syntax

HtmlImage Class   Img Element


Embeds an image control in a Web Forms document.

Declarative Syntax

For information on the individual members of this class, see HtmlImage in the class library.

Syntax Notes

  • This control does not require a closing tag.

Working with HtmlImage

The HtmlImage server control renders an image file specified by it’s Src property.

The HtmlImage control enables programming of the HTML <img> element, enabling developers to dynamically set and retrieve image attributes, including the image file’s src, width, height, border, alt, and align attributes.

This sample illustrates use of the HtmlImage control.

Changing a Displayed Image in Response to User Input

The following shows how to dynamically change a displayed image in a Web Forms page based on what the user chooses.

An HtmlSelect control provides the list of user options, in which the value selected determines the image to display.

Changing a Displayed Image in Response to User Input
Run Sample | View Source

The sample uses the click event of the HtmlInputButton control to trigger a handler that simply specifies the source path of the image file to be displayed, in this case, from the application’s /images directory.

<html>
<head>
<script language="C#" runat="server">
void submitHandler ( Object Sender, EventArgs e ) {
   image.Src = "images/" + imgSelector.Value;
}
</script>
</head>

<body>
<form runat="server">

   <p>Select image file: 
   <select id="imgSelector" runat="server">
      <option value="Earth.gif">Earth</option>
      <option value="Jupiter.gif">Jupiter</option>
      <option value="Mars.gif">Mars</option>
      <option value="Mercury.gif">Mercury</option>
      <option value="Neptune.gif">Neptune</option>
      <option value="Pluto.gif">Pluto</option>
      <option value="Uranus.gif">Uranus</option>
      <option value="Saturn.gif">Saturn</option>
      <option value="Venus.gif">Venus</option>
   </select>
   <input type=submit runat="server" value="Apply" onServerClick="chgImage">

   <p><img id="image" runat="server" src="/shared/images/earth.gif" /></p>

</form>
</body>
</html>
See Also

HtmlImage Class   Img Element   Web Forms Events and Handlers



© 2025 Reynald Nuñez and asp.net.ph. All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note