Image.AlternateText 屬性

定義

取得或設定當沒有影像時,要顯示於 Image 控制項的替代文字。 支援工具提示功能的瀏覽器將這個文字顯示為工具提示。

public:
 virtual property System::String ^ AlternateText { System::String ^ get(); void set(System::String ^ value); };
[System.ComponentModel.Bindable(true)]
public virtual string AlternateText { get; set; }
[<System.ComponentModel.Bindable(true)>]
member this.AlternateText : string with get, set
Public Overridable Property AlternateText As String

屬性值

在沒有影像時 Image 控制項中顯示的替代文字。

屬性

範例

下列範例示範如何使用 AlternateText 屬性來指定要在影像無法使用時顯示影像的替代文字。

<%@ Page Language="C#" %>
<!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>Image Example</title>
</head>
 
<body>

   <form id="form1" runat="server">

      <h3>Image Example</h3>

      <asp:Image id="Image1" runat="server"
           AlternateText="Image text"
           ImageAlign="left"
           ImageUrl="images/image1.jpg"/>
  
   </form>

</body>
</html>
<%@ Page Language="VB" %>
<!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>Image Example</title>
</head>
 
<body>

   <form id="form1" runat="server">

      <h3>Image Example</h3>

      <asp:Image id="Image1" runat="server"
           AlternateText="Image text"
           ImageAlign="left"
           ImageUrl="images/image1.jpg"/>
  
   </form>

</body>
</html>

備註

如果屬性中指定的 ImageUrl 影像無法使用,請使用這個屬性來指定要顯示的文字。 在支援工具提示功能的瀏覽器中,此文字也會顯示為工具提示。

當設定時,此屬性的值可以使用設計工具自動儲存到資源檔。 如需詳細資訊,請參閱 LocalizableAttributeASP.NET 全球化和當地語系化

適用於

另請參閱