Controls You Can Use on Web Forms ASP.NET Standard Controls Image Control
The Image Web server control enables you to display images on a Web Forms page and manage the images in server code.
The graphics file for an Image control is set by assigning a value to the control’s ImageUrl property. The ImageUrl can be specified declaratively at design time or dynamically at run time.
The below code snippet demonstrates how to declaratively assign a value to the ImageUrl property to display an image on this Web Forms page.
<asp:image id = "imgEarth" runat = "server"
imageurl = "/asp.net.ph/shared/images/earth.gif"
alternatetext = "Earth" />
The below example demonstrates how to programmatically assign a value to the ImageUrl property to display an image on a Web Forms page based on user input.
The ImageUrl can also be bound to a data source to display graphics based on database information.
The below examples demonstrate different ways of dynamically assigning a value to the ImageUrl property based on database information.
In addition to displaying a graphic, the Image control allows you to specify various types of text for the image, using the following properties.
Property |
Description |
ToolTip |
This is the text that is displayed as advisory information for the image. Note that not all browsers support the ToolTip property. |
AlternateText |
This is the text that is displayed if the graphics file cannot be found. If no ToolTip property is specified, browsers that support the property will use the AlternateText value as a ToolTip. |
GenerateEmptyAlternateText |
If this property is set to true, the alt attribute of the rendered image element will be set to an empty string. |
Unlike most other Web server controls, the Image control does not support any events. For example, the Image control does not respond to mouse clicks. To create an interactive image, you can instead use the ImageMap or the ImageButton Web server controls.
Adding Image Controls to a Web Forms Page