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.
- Declare an <
asp:Image
> element on the page. For syntax, see Image Control Syntax.
- Set the control’s ImageUrl property to the URL of a .gif, .jpg, or other Web graphic file.
- 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.
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.
Introduction to the Image Control