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

属性值

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 全球化和本地化

适用于

另请参阅