Share via


HtmlImage.Src Propriedade

Definição

Obtém ou define a origem do arquivo de imagem a ser exibido.

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 da propriedade

String

Uma cadeia de caracteres que contém o caminho para um arquivo de imagem a ser exibido.

Exemplos

O exemplo de código a seguir demonstra como usar a Src propriedade para especificar um arquivo de imagem a ser exibido no mesmo diretório que o arquivo de origem da página da 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>

O exemplo de código a seguir demonstra como usar a Src propriedade para especificar um arquivo de imagem a ser exibido em um diretório diferente do arquivo de origem da página da 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>

Comentários

Use essa propriedade para especificar o caminho para o arquivo de imagem a ser exibido. Se o arquivo de imagem estiver no mesmo diretório que o arquivo de origem da página da Web que o usa, basta especificar o nome do arquivo. Caso contrário, você também deve incluir o caminho para o arquivo. O caminho pode ser absoluto ou relativo ao diretório que contém o arquivo de origem da página da Web. Você pode usar o caminho relativo " " ~/ para fazer referência ao diretório virtual atual em que a página está localizada. Por exemplo, o valor de Src <img runat="server" src="~/abc/d.gif"> uma página no diretório virtual "XspTest" é <img src="/XspText/abc/d.gif">.

Aplica-se a