This documentation is archived and is not being maintained.

Image Class

Displays an image on a Web page.

Namespace:  System.Web.UI.WebControls
Assembly:  System.Web (in System.Web.dll)

[AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
[AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
public class Image : WebControl
<asp:Image />

The Image control lets you work with images from server code. Use the Image control to display any valid image supported by the requesting browser on the Web page. The path to the displayed image is specified by setting the ImageUrl property. You can specify the text to display in place of image when the image is not available by setting the AlternateText property. The alignment of the image in relation to other elements on the Web page is specified by setting ImageAlign property.


This control only displays an image. If you need to capture mouse clicks on the image, use the ImageButton control.


The markup rendered by default for this control might not conform to accessibility standards such as the Web Content Accessibility Guidelines 1.0 (WCAG) priority 1 guidelines. For details about accessibility support for this control, see ASP.NET Controls and Accessibility.

How to: Add Image Web Server Controls to a Web Forms PageBuilding ASP .NET Web Applications
How to: Add Image Web Server Controls to a Web Forms PageBuilding ASP .NET Web Applications
Walkthrough: Creating and Using ASP.NET Master Pages in Visual Web DeveloperBuilding ASP .NET Web Applications in Visual Studio
Walkthrough: Creating an Accessible Web ApplicationBuilding ASP .NET Web Applications in Visual Studio
How to: Add Image Web Server Controls to a Web Forms Page (Visual Studio)Building ASP .NET Web Applications in Visual Studio

The following example demonstrates how to create an Image control on a Web page.


The following code sample uses the single-file code model and may not work correctly if copied directly into a code-behind file. This code sample must be copied into an empty text file that has an .aspx extension. For more information on the Web Forms code model, see ASP.NET Web Page Code Model.

<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
<html xmlns="" >
    <title>Image Example</title>
<script language="C#" runat="server">

      void Button_Click(Object sender, EventArgs e)
            case 0:
               Image1.ImageAlign = ImageAlign.NotSet;

            case 1:
               Image1.ImageAlign = ImageAlign.Left;

            case 2:
               Image1.ImageAlign = ImageAlign.Right;

            case 3:
               Image1.ImageAlign = ImageAlign.Baseline;

            case 4:
               Image1.ImageAlign = ImageAlign.Top;

            case 5:
               Image1.ImageAlign = ImageAlign.Middle;

            case 6:
               Image1.ImageAlign = ImageAlign.Bottom;

            case 7:
               Image1.ImageAlign = ImageAlign.AbsBottom;

            case 8:
               Image1.ImageAlign = ImageAlign.AbsMiddle;

            case 9:
               Image1.ImageAlign = ImageAlign.TextTop;

               Image1.ImageAlign = ImageAlign.NotSet;






   <form id="form1" runat="server">

      <h3>Image Example</h3>

      <div style="font-size:large">

         Text Text Text Text Text Text Text Text Text Text Text Text 
         Text Text Text Text Text Text Text Text Text Text Text Text 
         Text Text Text Text Text Text Text Text Text Text Text Text


      <asp:Image id="Image1" runat="server"
           AlternateText="Image text"

      <hr />

      Select Image Align: <br />

      <asp:DropDownList id="DropList1"



      <br /><br />

      <asp:Button id="Button1"
           Text="Apply Image Alignment"



Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0