asp.net.ph

Image.ImageUrl Property

System.Web.UI.WebControls Namespace   Image Class


Sets or retrieves the path to an image file.

Syntax


Inline <asp:image imageurl = strUrl ... >
Script Image.ImageUrl [ = strUrl ]

Property Value


strUrl String that specifies the path to an image file to display.

The property is read/write with no default value.

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 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 Image 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

<asp:image imageurl = "~/shared/myGraphic.png" runat = "server" >

will resolve to the absolute path

<asp:image imageurl = "/shared/myGraphic.png" runat = "server">

In certain cases, as when images or imagebuttons ( which inherit this property ) are used within templated controls, the ImageUrl property is usually obtained dynamically from a data source.

Example

The following example shows how to declaratively set the ImageUrl property of an Image control at design time.

<asp:image imageurl = "~/shared/aspxtreme.jpg" width=100 height=30 border=0 
   alternatetext = "Simply awesome" imagealign = "right" runat = "server" />

The following examples demonstrate how to dynamically bind the ImageUrl property of Image or ImageButton controls defined within templates.

Dynamically Generated ImageButtons
Run Sample | View Source
DataGrid SelectedIndexChanged Event
Run Sample | View Source
See Also

Image Members Skip Navigation Links




Home
Suggested Reading


Previous page Back to top Next page

© 2000-2010 Rey Nuñez All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note

You can help support asp.net.ph