This documentation is archived and is not being maintained.

HtmlImage.Src Property

Gets or sets the source of the image file to display.

[Visual Basic]
Public Property Src As String
[C#]
public string Src {get; set;}
[C++]
public: __property String* get_Src();
public: __property void set_Src(String*);
[JScript]
public function get Src() : String;
public function set Src(String);

Property Value

A string that contains the path to an image file to display.

Remarks

Use this property to specify the path to the image file to display. If the image file is in the same directory as the Web page source file that uses it, you can just specify the file name. Otherwise, you must also include the path to the file. The path can be absolute or relative to the directory that contains the Web page source file. You can use the relative path " ~/ " to refer to the current virtual directory where the page is located. For example, the value of Src for <img runat="server" src="~/abc/d.gif"> on a page in the "XspTest" virtual directory is <img src="/XspText/abc/d.gif">.

If the path is relative, it is automatically converted to an absolute path when the HtmlImage control is rendered on the browser. This allows user controls (.ascx files) to be more portable.

Example

[Visual Basic, C#, JScript] The following example demonstrates how to use the Src property to specify an image file to display in the same directory as the Web page source file.

[Visual Basic] 
<%@ Page Language="VB" AutoEventWireup="True" %>
<html>
 <head>
 
 </head>
 
 <body>
 
    <form runat="server">
 
       <h3>HtmlImage Example</h3>
     
       <img id ="Image1"
            Src="image1.jpg"
            Width="500"
            Height="226"
            Alt="Image 1"
            Border="5"
            Align="center" 
            runat=server/>
    
    </form>
 
 </body>
 </html>


[C#] 
<%@ Page Language="C#" AutoEventWireup="True" %>
<html>
 <head>
 
 </head>
 
 <body>
 
    <form runat="server">
 
       <h3>HtmlImage Example</h3>
     
       <img id ="Image1"
            Src="image1.jpg"
            Width="500"
            Height="226"
            Alt="Image 1"
            Border="5"
            Align="center" 
            runat=server/>
    
    </form>
 
 </body>
 </html>


[JScript] 
<%@ Page Language="JScript" AutoEventWireup="True" %>
<html>
 <head>
 
 </head>
 
 <body>
 
    <form runat="server">
 
       <h3>HtmlImage Example</h3>
     
       <img id ="Image1"
            Src="image1.jpg"
            Width="500"
            Height="226"
            Alt="Image 1"
            Border="5"
            Align="center" 
            runat=server/>
    
    </form>
 
 </body>
 </html>

[Visual Basic, C#, JScript] The following example demonstrates how to use the Src property to specify an image file to display in a different directory from the Web page source file.

[Visual Basic] 
<%@ Page Language="VB" AutoEventWireup="True" %>
<html>
 <head>
 
 </head>
 
 <body>
 
    <form runat="server">
 
       <h3>HtmlImage Example</h3>
     
       <img id ="Image1"
            Src="images/image1.jpg"
            Width="500"
            Height="226"
            Alt="Image 1"
            Border="5"
            Align="center" 
            runat=server/>
    
    </form>
 
 </body>
 </html>

[C#] 
<%@ Page Language="C#" AutoEventWireup="True" %>
<html>
 <head>
 
 </head>
 
 <body>
 
    <form runat="server">
 
       <h3>HtmlImage Example</h3>
     
       <img id ="Image1"
            Src="images/image1.jpg"
            Width="500"
            Height="226"
            Alt="Image 1"
            Border="5"
            Align="center" 
            runat=server/>
    
    </form>
 
 </body>
 </html>

[JScript] 
<%@ Page Language="JScript" AutoEventWireup="True" %>
<html>
 <head>
 
 </head>
 
 <body>
 
    <form runat="server">
 
       <h3>HtmlImage Example</h3>
     
       <img id ="Image1"
            Src="images/image1.jpg"
            Width="500"
            Height="226"
            Alt="Image 1"
            Border="5"
            Align="center" 
            runat=server/>
    
    </form>
 
 </body>
 </html>

[C++] No example is available for C++. To view a Visual Basic, C#, or JScript example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

See Also

HtmlImage Class | HtmlImage Members | System.Web.UI.HtmlControls Namespace

Show: