HOME

ASP.NET Tutorial
ASP.NET HOME
ASP.NET Intro
ASP.NET vs ASP
ASP.NET Install
ASP.NET Pages
ASP.NET Controls
ASP.NET Events

References
HTML Controls
Web Controls
Validation Controls
Download XMLSpy here
Please visit our sponsors !

HtmlImage Control

Back

Definition and Usage

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


Properties

Property Description
Align How to align the image according to surrounding elements. Legal values are:
  • top
  • middle
  • bottom
  • left
  • right
Alt A short description of the image
Border The width of the borders around the image
Height The height of the image
id A unique id for the control
runat Specifies that the control is a server control.  Must be set to "server"
Src The URL of the image to display
Width The width of the image

Example 1

In the following example we declare an HtmlImage control in an .aspx file (remember to embed the control inside an HtmlForm control). Then we modify the src and border property 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 many events that ASP.NET understands:

<script runat="server">
  Sub Page_Load(Sender As Object,E As EventArgs)
    i1.Src="../images/smiley.gif"
    i1.Border="1"
  End Sub
</script>
<html>
<body>
<form runat="server">
<img id="i1" runat="server"/>
</form>
</body>
</html>

Example 2

In the following example we declare an HtmlImage and an HTMLSelect control in an .aspx file (remember to embed the controls inside an HtmlForm control). Then we modify the src property of the HtmlImage control based on user choices. The value selected in the HtmlSelect control determines which image to display:

<script runat="server">
  Sub change_image(Sender As Object, e As EventArgs)
    i1.Src = "../images/" & s1.Value
  End Sub
</script>
<html>
<body>
<form runat="server">
<img id="i1" src="../images/smiley.gif" runat="server"/>
<br />
<p>Select image:
<select id="s1" runat="server">
  <option value="smiley.gif">Smiley</option>
  <option value="angry.gif">Angry</option>
  <option value="stickman.gif">Stickman</option>
</select>
<input type="submit" runat="server" value="Show Image"
OnServerClick="change_image">
</p>
</form>
</body>
</html>


Back

Jump to: Top of Page or HOME or Printer Friendly Printer friendly page


Search W3Schools:


What Others Say About Us

Does the world know about us? Check out these places:

Dogpile Alta Vista MSN Google Excite Lycos Yahoo Ask Jeeves


We Help You For Free. You Can Help Us!


W3Schools is for training only. We do not warrant its correctness or its fitness for use. The risk of using it remains entirely with the user. While using this site, you agree to have read and accepted our terms of use and privacy policy.

Copyright 1999-2002 by Refsnes Data. All Rights Reserved


Validate How we converted to XHTML Validate

IISCart
ASP Ecommerce & Shopping Cart


Your own Web Site?

Read W3Schools
Hosting Tutorial



$15 Domain Name
Registration
Save $20 / year!



Advertise
at W3Schools

Only 0.5 CPM



SELECTED LINKS

University Online
Master Degree
Bachelor Degree


Web Software

The Future of
Web Development


Jobs and Careers

Web Security
Web Statistics
Web Standards


PARTNERS

W3Schools
TopXML
VisualBuilder
XMLPitstop
DevelopersDex
DevGuru
Programmers Heaven
The Code Project
Tek Tips Forum
ZVON.ORG
TopXML Search