HtmlImage.Src Propiedad

Definición

Obtiene o establece el origen del archivo de imagen que se va a mostrar.

public:
 property System::String ^ Src { System::String ^ get(); void set(System::String ^ value); };
public string Src { get; set; }
member this.Src : string with get, set
Public Property Src As String

Valor de propiedad

String

Cadena que contiene la ruta de acceso al archivo de imagen que se va a mostrar.

Ejemplos

En el ejemplo de código siguiente se muestra cómo usar la Src propiedad para especificar un archivo de imagen que se va a mostrar en el mismo directorio que el archivo de origen de la página web.

<%@ Page Language="C#" AutoEventWireup="True" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
 <head>
    <title>HtmlImage Example</title>
</head>
 
 <body>
 
    <form id="form1" runat="server">
 
       <h3>HtmlImage Example</h3>
     
       <img id ="Image1"
            src="Image1.jpg"
            alt="Image 1"
            runat="server"
            style="width:500; height:226; border:5; text-align:center" />
    
    </form>
 
 </body>
 </html>
<%@ Page Language="VB" AutoEventWireup="True" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
 <head>
    <title>HtmlImage Example</title>
</head>
 
 <body>
 
    <form id="form1" runat="server">
 
       <h3>HtmlImage Example</h3>
     
       <img id ="Image1"
            src="Image1.jpg"
            alt="Image 1"
            runat="server"
            style="width:500; height:226; border:5; text-align:center" />
    
    </form>
 
 </body>
 </html>

En el ejemplo de código siguiente se muestra cómo usar la Src propiedad para especificar un archivo de imagen que se va a mostrar en un directorio diferente del archivo de origen de la página web.

<%@ Page Language="C#" AutoEventWireup="True" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
 <head>
    <title>HtmlImage Example</title>
</head>
 
 <body>
 
    <form id="form1" runat="server">
 
       <h3>HtmlImage Example</h3>
     
       <img id ="Image1"
            src="Image1.jpg"
            alt="Image 1"
            runat="server"
            style="width:500; height:226; border:5; text-align:center" />
    
    </form>
 
 </body>
 </html>
<%@ Page Language="VB" AutoEventWireup="True" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
 <head>
    <title>HtmlImage Example</title>
</head>
 
 <body>
 
    <form id="form1" runat="server">
 
       <h3>HtmlImage Example</h3>
     
       <img id ="Image1"
            src="Image1.jpg"
            alt="Image 1"
            runat="server"
            style="width:500; height:226; border:5; text-align:center" />
    
    </form>
 
 </body>
 </html>

Comentarios

Utilice esta propiedad para especificar la ruta de acceso al archivo de imagen que se va a mostrar. Si el archivo de imagen está en el mismo directorio que el archivo de origen de la página web que lo usa, solo puede especificar el nombre de archivo. De lo contrario, también debe incluir la ruta de acceso al archivo. La ruta de acceso puede ser absoluta o relativa al directorio que contiene el archivo de origen de la página web. Puede usar la ruta de acceso relativa " ~/ " para hacer referencia al directorio virtual actual donde se encuentra la página. Por ejemplo, el valor de Src para <img runat="server" src="~/abc/d.gif"> en una página del directorio virtual "XspTest" es <img src="/XspText/abc/d.gif">.

Se aplica a