AdRotator.AdCreated Événement

Définition

Se produit une fois par aller-retour vers le serveur après la création du contrôle et avant que la page soit rendue.

public:
 event System::Web::UI::WebControls::AdCreatedEventHandler ^ AdCreated;
public event System.Web.UI.WebControls.AdCreatedEventHandler AdCreated;
member this.AdCreated : System.Web.UI.WebControls.AdCreatedEventHandler 
Public Custom Event AdCreated As AdCreatedEventHandler 

Type d'événement

Exemples

L’exemple de code suivant montre comment spécifier et coder un gestionnaire pour l’événement AdCreated . Il obtient l’URL associée à la publicité, lorsque le AdRotator contrôle est créé, et l’affiche sous le contrôle.

Notes

L’exemple de code suivant utilise le modèle de code à fichier unique et peut ne pas fonctionner correctement s’il est copié directement dans un fichier code-behind. Cet exemple de code doit être copié dans un fichier texte vide qui a une extension .aspx. Pour plus d’informations sur le modèle de code Web Forms, consultez ASP.NET Web Forms Modèle de code de page.

<%@ 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>AdRotator Example</title>
</head>
 
    <script language="c#" runat="server">
       void AdCreated_Event(Object sender, AdCreatedEventArgs e) 
       {
          Message.Text=e.NavigateUrl;   
       }      
    </script>
 
 <body>
 
    <form id="form1" runat="server">
 
       <h3>AdRotator Example</h3>
 
       <asp:AdRotator id="test1" runat="server"
            AdvertisementFile = "~/App_Data/Ads.xml"
            Borderwidth="1"
            Target="_blank"
            OnAdCreated="AdCreated_Event"/><br /><br />
 
       <asp:label id="Message" runat="server"/>
 
    </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>AdRotator Example</title>
</head>
 
    <script language="vb" runat="server">
       Sub AdCreated_Event(sender As Object, e As AdCreatedEventArgs) 
          Message.Text=e.NavigateUrl
       End Sub
    </script>
 
 <body>
 
    <form id="form1" runat="server">
 
       <h3>AdRotator Example</h3>
 
       <asp:AdRotator id="test1" runat="server"
            AdvertisementFile = "~/App_Data/Ads.xml"
            Borderwidth="1"
            Target="_blank"
            OnAdCreated="AdCreated_Event"/><br /><br />
 
       <asp:label id="Message" runat="server"/>
 
    </form>
 
 </body>
 </html>

L’exemple de code suivant montre comment mettre en forme le fichier XML qui contient les informations de publication. Pour plus d’informations sur le fichier XML, consultez la AdvertisementFile propriété .

<Advertisements>  
  <Ad>  
    <ImageUrl>~/Images/image1.jpg</ImageUrl>  
    <Height>60</Height>  
    <Width>190</Width>  
    <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>~/Images/image2.jpg</ImageUrl>  
    <Height>90</Height>  
    <Width>90</Width>  
    <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>  

Notes

L’exemple de code suivant utilise le modèle de code à fichier unique et peut ne pas fonctionner correctement s’il est copié directement dans un fichier code-behind. Cet exemple de code doit être copié dans un fichier texte vide qui a une extension .aspx. Pour plus d’informations sur le modèle de code Web Forms, consultez ASP.NET Web Forms Modèle de code de page.


<%@ 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>AdRotator AdCreated Example</title>
</head>
 
   <script runat="server">

      void Page_Load(Object sender, EventArgs e)
      {

         // Create an EventHandler delegate for the method you want to handle the event
         // and then add it to the list of methods called when the event is raised.
         Ad.AdCreated += new System.Web.UI.WebControls.AdCreatedEventHandler(this.AdCreated_Event);

      }

      void AdCreated_Event(Object sender, AdCreatedEventArgs e) 
      {

         // Override the AlternateText value from the ads.xml file.
         e.AlternateText = "Visit this site!";   

      }      

   </script>
 
<body>
 
   <form id="form1" runat="server">
 
      <h3>AdRotator AdCreated Example</h3>

      Notice that the AlternateText property of the advertisement <br />
      has been programmatically modified from the value in the XML <br />
      file. 

      <br /><br />
 
      <asp:AdRotator id="Ad" runat="server"
           AdvertisementFile = "~/App_Data/Ads.xml"
           Borderwidth="1"
           Target="_blank"/>
 
   </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>AdRotator AdCreated Example</title>
</head>
 
   <script runat="server">

      Sub Page_Load(sender As Object, e As EventArgs)

         ' Create an EventHandler delegate for the method you want to handle the event
         ' and then add it to the list of methods called when the event is raised.
         AddHandler Ad.AdCreated, AddressOf AdCreated_Event

      End Sub

      Sub AdCreated_Event(sender As Object, e As AdCreatedEventArgs) 

         ' Override the AlternateText value from the ads.xml file.
         e.AlternateText = "Visit this site!"   

      End Sub      

   </script>
 
<body>
 
   <form id="form1" runat="server">
 
      <h3>AdRotator AdCreated Example</h3>

      Notice that the AlternateText property of the advertisement <br />
      has been programmatically modified from the value in the XML <br />
      file. 

      <br /><br />
 
      <asp:AdRotator id="Ad" runat="server"
           AdvertisementFile = "~/App_Data/Ads.xml"
           Borderwidth="1"
           Target="_blank"/>
 
   </form>
 
</body>
</html>

Remarques

Cet événement est déclenché une fois par aller-retour vers le serveur après la création du contrôle, mais avant le rendu de la page. Lorsque la AdvertisementFile propriété est définie, cet événement se produit une fois que la publication a été sélectionnée dans le fichier.

Vous pouvez contrôler l’affichage du AdRotator contrôle en modifiant les arguments passés au gestionnaire d’événements de l’événement AdCreated . Si la AdvertisementFile propriété n’est pas définie, cela vous permet de spécifier directement les informations de publication, sans utiliser un fichier de publication distinct. Si la AdvertisementFile propriété est définie, cela vous permet d’étendre le comportement du AdRotator contrôle, par exemple la redirection vers une autre page.

Notes

Lorsque la mise en cache des pages est activée, un AdRotator contrôle n’est pas mis en cache. Une nouvelle publicité est sélectionnée chaque fois que la page web est actualisée. Toutefois, une nouvelle publication n’est pas sélectionnée si vous fournissez un gestionnaire d’événements pour l’événement AdCreated .

Pour plus d'informations sur la gestion des événements, voir gestion et déclenchement d’événements.

S’applique à

Voir aussi