AdRotator.AdCreated Evento

Definição

Ocorre uma vez por viagem de ida e volta ao servidor após a criação do controle, mas antes de a página ser renderizada.Occurs once per round trip to the server after the creation of the control, but before the page is rendered.

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 

Tipo de evento

AdCreatedEventHandler

Exemplos

O exemplo de código a seguir demonstra como especificar e codificar um manipulador para o AdCreated evento.The following code example demonstrates how to specify and code a handler for the AdCreated event. Ele obtém a URL associada ao anúncio, quando o AdRotator controle é criado e o exibe abaixo do controle.It gets the URL associated with the advertisement, when the AdRotator control is created, and displays it below the control.

Observação

O exemplo de código a seguir usa o modelo de código de arquivo único e pode não funcionar corretamente se copiado diretamente para um arquivo code-behind.The following code sample uses the single-file code model and may not work correctly if copied directly into a code-behind file. Este exemplo de código deve ser copiado em um arquivo de texto vazio que tenha uma extensão. aspx.This code sample must be copied into an empty text file that has an .aspx extension. Para obter mais informações sobre o modelo de código Web Forms, consulte modelo de código de página do ASP.NET Web Forms.For more information on the Web Forms code model, see ASP.NET Web Forms Page Code Model.

<%@ 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>
    

O exemplo de código a seguir demonstra como formatar o arquivo XML que contém as informações de anúncio.The following code example demonstrates how to format the XML file that contains the advertisement information. Para obter mais informações sobre o arquivo XML, consulte a AdvertisementFile propriedade.For more information on the XML file, see the AdvertisementFile property.

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

Observação

O exemplo de código a seguir usa o modelo de código de arquivo único e pode não funcionar corretamente se copiado diretamente para um arquivo code-behind.The following code sample uses the single-file code model and may not work correctly if copied directly into a code-behind file. Este exemplo de código deve ser copiado em um arquivo de texto vazio que tenha uma extensão. aspx.This code sample must be copied into an empty text file that has an .aspx extension. Para obter mais informações sobre o modelo de código Web Forms, consulte modelo de código de página do ASP.NET Web Forms.For more information on the Web Forms code model, see ASP.NET Web Forms Page Code Model.


<%@ 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>

Comentários

Esse evento é gerado uma vez por viagem de ida e volta ao servidor após a criação do controle, mas antes da página ser renderizada.This event is raised once per round trip to the server after the creation of the control, but before the page is rendered. Quando a AdvertisementFile propriedade é definida, esse evento ocorre depois que o anúncio é selecionado no arquivo.When the AdvertisementFile property is set, this event occurs after the advertisement has been selected from the file.

Você pode controlar como o AdRotator controle é exibido modificando os argumentos passados para o manipulador de eventos do AdCreated evento.You can control how the AdRotator control is displayed by modifying the arguments passed to the event handler of the AdCreated event. Se a AdvertisementFile propriedade não estiver definida, isso permitirá que você especifique as informações de anúncio diretamente, sem usar um arquivo de anúncio separado.If the AdvertisementFile property is not set, this allows you to specify the advertisement information directly, without using a separate advertisement file. Se a AdvertisementFile propriedade for definida, isso permitirá que você estenda o comportamento do AdRotator controle, como redirecionar para outra página.If the AdvertisementFile property is set, this allows you to extend the behavior of the AdRotator control, such as redirecting to another page.

Observação

Quando o cache de página está habilitado, um AdRotator controle não é armazenado em cache.When page caching is enabled, an AdRotator control is not cached. Um novo anúncio é selecionado sempre que a página da Web é atualizada.A new advertisement is selected whenever the Web page refreshes. No entanto, um novo anúncio não será selecionado se você fornecer um manipulador de eventos para o AdCreated evento.A new advertisement is not selected, however, if you provide an event handler for the AdCreated event.

Para obter mais informações sobre como manipular eventos, consulte manipulando e gerando eventos.For more information about handling events, see Handling and Raising Events.

Aplica-se a

Confira também