System.Web.UI.HtmlControls Namespace HtmlImage Class
Sets or retrieves the source of the image file to display.
Inline |
<img src = strUrl ... > |
Script |
HtmlImage.Src [ = strUrl ] |
strUrl |
String that specifies the path to an image file to display. |
The property is read/write with no default value.
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 that uses it, simply specify the file name. Otherwise, include the path to the file.
The path can be absolute or relative to the directory where the Web page is located. You can use the relative path symbol [ ~/ ] to refer to the application root or virtual directory. If the path is relative, it is automatically converted to an absolute path when the HtmlImage control is rendered on the browser.
This allows images, as well as other files that a Web page may be dependent on, such as user controls ( .ascx files ), to be more portable.
For example, assuming the application virtual directory is aspxtreme, the path specified in the following declaration
<img src="~/shared/graphic1.gif" runat="server" >
will resolve to the absolute path
<img src="/shared/graphic1.gif" runat="server">
The below code shows how to declaratively set the Src property of an HtmlImage control at design time.
<img src="~/shared/aspxtreme.jpg" width=100 height=30 border=0
alt="Simply awesome" align="right" runat="server" />
HtmlImage Members