asp.net.ph

Skip Navigation Links

Adding Image Controls to a Web Forms Page

Controls You Can Use on Web Forms   ASP.NET Standard Controls   Image Control


Basically, to create a working Image control, you need to add the control to the page and specify the graphics file.

  1. Declare an <asp:Image> element on the page. For syntax, see Image Control Syntax.
  2. Set the control’s ImageUrl property to the URL of a .gif, .jpg, or other Web graphic file.
  3. Optionally set the following Image control properties.

Property Description
Height and Width Reserve space for the graphic on the page and resize the graphic to fit the reserved space. The image will be sized to fit the space you reserve.
ImageAlign Aligns the image with respect to surrounding text, using values such as Top, Bottom, Left, Middle, and Right. In code, image alignment is set using the ImageAlign enumeration.
AlternateText Displays text in place of the graphic if the graphic cannot be loaded. In some browsers, this text is also displayed as a ToolTip.

The below example demonstrates how to initially declare values for the ImageUrl and AlternateText properties of an Image control at design time, and how to programmatically assign values for both properties at run time based on user input.

Image Control Example
Run Sample | View Source

The ImageUrl property can also be bound to a data source to display graphics based on database information, as when an Image control is used within templated controls such as a DataGrid, DataList, GridView, FormView or Repeater.

The below examples demonstrate different ways of dynamically assigning a value to the ImageUrl property based on database information.

FormView DataBound Event Example
Run Sample | View Source
FormView with Nested GridView
Run Sample | View Source
DataList ItemDataBound Event Example
Run Sample | View Source
See Also

Introduction to the Image Control



© 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