asp.net.ph

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

HtmlImage Control Syntax

ASP.NET Syntax   ASP.NET Syntax for HTML Controls


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 example 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 ) {
   Image1.Src = "images/" + Select1.Value;
}
</script>
</head>

<body>

<form runat="server">

   <img id="Image1" src = "images/cereal1.gif" runat="server" />

   <p>Select image file: </p>

   <select id="Select1" runat="server">
      <option value="Cereal1.gif">Healthy Grains</option>
      <option value="Cereal2.gif">Corn Flake Cereal</option>
      <option value="Cereal3.gif">U.F.O.S</option>
      <option value="Cereal4.gif">Oatey O’s</option>
      <option value="Cereal5.gif">Strike</option>
      <option value="Cereal7.gif">Fruity Pops</option>
   </select>

   <input type = "submit" runat="server" value="Apply"
      onServerClick = "submitHandler">

</form>

</body>
</html>
See Also

Web Forms Events and Handlers   HtmlImage Class



© 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