AdCreatedEventArgs.ImageUrl 屬性

定義

取得或設定 AdRotator 控制項中顯示的影像的 URL。

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

屬性值

AdRotator 控制項中顯示的影像 URL, 預設值是 Empty

範例

下列程式碼範例示範如何以程式設計方式設定 ImageUrl 屬性。

<%@ 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 runat="server">
    <title>AdCreatedEventArgs ImageUrl Example</title>
<script runat="server">
   
       void AdCreated_Event(Object sender, AdCreatedEventArgs e) 
       {

          e.ImageUrl = "images/newimage.jpg";   
       
       }      

   </script>
 
</head>
 
<body>
 
   <form id="form1" runat="server">
 
      <h3>AdCreatedEventArgs ImageUrl Example</h3>
 
      <asp:AdRotator id="AdRotator1" runat="server"
           AdvertisementFile = "Ads.xml"
           Target="_newwwindow"
           OnAdCreated="AdCreated_Event"/>
 
   </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 runat="server">
    <title>AdCreatedEventArgs ImageUrl Example</title>
<script runat="server">
   
       Sub AdCreated_Event(sender As Object, e As AdCreatedEventArgs) 
       
          e.ImageUrl = "images/newimage.jpg"   
       
       End Sub      

   </script>
 
</head>
 
<body>
 
   <form id="form1" runat="server">
 
      <h3>AdCreatedEventArgs ImageUrl Example</h3>
 
      <asp:AdRotator id="AdRotator1" runat="server"
           AdvertisementFile = "Ads.xml"
           Target="_newwwindow"
           OnAdCreated="AdCreated_Event"/>
 
   </form>
 
</body>
</html>

下列程式碼範例示範如何格式化包含廣告資訊的 XML 檔案。 如需 XML 檔案的詳細資訊,請參閱 AdvertisementFile 類別的 AdRotator 屬性。

<Advertisements>  
 <Ad>  
 <ImageUrl>image1.jpg</ImageUrl>  
 <NavigateUrl>http://www.microsoft.com</NavigateUrl>  
 <AlternateText>Microsoft Main Site</AlternateText>  
 <Impressions>80</Impressions>  
 <Keyword>Topic1</Keyword>  
 <Caption>This is the caption for Ad#1</Caption>   
 </Ad>  
 <Ad>  
 <ImageUrl>image2.jpg</ImageUrl>  
 <NavigateUrl>http://www.wingtiptoys.com</NavigateUrl>  
 <AlternateText>Wingtip Toys</AlternateText>  
 <Impressions>80</Impressions>  
 <Keyword>Topic2</Keyword>  
 <Caption>This is the caption for Ad#2</Caption>   
 </Ad>  
</Advertisements>  

備註

ImageUrl使用 屬性來指定要在 控制項中顯示廣告之影像的 AdRotator URL。 您可以使用相對 URL 或絕對 URL。 相對 URL 會將影像的位置與網頁或使用者控制項的位置建立關聯,而不指定伺服器上的完整路徑。 路徑相對於網頁的位置。 這可讓您更輕鬆地將整個網站移至伺服器上的另一個目錄,而不需更新程式碼中的映射路徑。 絕對 URL 會提供完整的路徑,因此將網站移至另一個目錄需要更新程式碼。

個別的 XML 檔案包含所顯示廣告的屬性。 控制項 AdRotator 會自動在包含廣告資訊的 XML 檔案中,使用對應的影像 URL 專案來設定 ImageUrl 屬性。 這個屬性也可以用來以程式設計方式設定影像 URL。

注意

如果您使用廣告檔案並指定此屬性的相對 URL,URL 會相對於廣告檔案所在的目錄。 如果您直接使用相對 URL 來設定此屬性,而不是使用廣告檔案,則 URL 會相對於包含 AdRotator 控制項的頁面或使用者控制項目錄。

適用於

另請參閱