Export (0) Print
Expand All
4 out of 10 rated this helpful - Rate this topic

Image Class

Displays an image on a Web page.

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

public class Image : WebControl
public class Image extends WebControl
public class Image extends WebControl

Use the Image control to display an image 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.

NoteNote

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

Accessibility

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.

TopicLocation
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
How to: Add Image Web Server Controls to a Web Forms Page (Visual Studio)Building ASP .NET Web Applications in Visual Studio
Walkthrough: Creating an Accessible Web ApplicationBuilding ASP .NET Web Applications in Visual Studio

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

NoteNote

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#" %>
<html>
<head>

   <script language="C#" runat="server">

      void Button_Click(Object sender, EventArgs e)
      {
         switch(DropList1.SelectedIndex)
         {
            case 0:
               Image1.ImageAlign = ImageAlign.NotSet;
               break;
         
            case 1:
               Image1.ImageAlign = ImageAlign.Left;
               break;

            case 2:
               Image1.ImageAlign = ImageAlign.Right;
               break;

            case 3:
               Image1.ImageAlign = ImageAlign.Baseline;
               break;

            case 4:
               Image1.ImageAlign = ImageAlign.Top;
               break;

            case 5:
               Image1.ImageAlign = ImageAlign.Middle;
               break;

            case 6:
               Image1.ImageAlign = ImageAlign.Bottom;
               break;
         
            case 7:
               Image1.ImageAlign = ImageAlign.AbsBottom;
               break;

            case 8:
               Image1.ImageAlign = ImageAlign.AbsMiddle;
               break;

            case 9:
               Image1.ImageAlign = ImageAlign.TextTop;
               break;

            default:
               Image1.ImageAlign = ImageAlign.NotSet;
               break;

         }

      }

   </script>

</head>
 
<body>

   <form runat="server">

      <h3>Image Example</h3>

      <font size="5">

         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

      </font> 
 
      <asp:Image id="Image1" runat="server"
           AlternateText="Image Text"
           ImageAlign="left"
           ImageUrl="images/image1.jpg"/>

      <hr>
    
      Select Image Align: <br>

      <asp:DropDownList id="DropList1"
           runat="server">

         <asp:ListItem>NotSet</asp:ListItem>
         <asp:ListItem>Left</asp:ListItem>
         <asp:ListItem>Right</asp:ListItem>
         <asp:ListItem>BaseLine</asp:ListItem>
         <asp:ListItem>Top</asp:ListItem>
         <asp:ListItem>Middle</asp:ListItem>
         <asp:ListItem>Bottom</asp:ListItem>
         <asp:ListItem>AbsBottom</asp:ListItem>
         <asp:ListItem>AbsMiddle</asp:ListItem>
         <asp:ListItem>TextTop</asp:ListItem>     

      </asp:DropDownList>

      <br><br>

      <asp:Button id="Button1"
           Text="Apply Image Alignment"
           OnClick="Button_Click" 
           runat="server"/>
  
   </form>

</body>
</html>
   

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 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

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

.NET Framework

Supported in: 2.0, 1.1, 1.0
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.