ASP.NET notes how to use advertising controls

  • 2020-06-03 06:19:34
  • OfStack

How to use advertising controls:

The AD file is an XML file. All tag attributes in the AD file are analyzed and put into the adProperties dictionary for attribute editing.

ads.xml


<?xml version="1.0" encoding="utf-8"?>
  <!-- The advertising file is 1 a XML file -->
 <Advertisements>
   <Ad>
     <ImageUrl>4rwbgzby.gif</ImageUrl>
     <NavigateUrl>https://www.ofstack.com</NavigateUrl>
     <AlternateText>Text_01</AlternateText>
     <KeyWord>one</KeyWord>
     <Impressions>40</Impressions>
     <Aniaml>I'm using adRotator  No.1</Aniaml>
   </Ad>

   <Ad>
     <ImageUrl>banner.jpg</ImageUrl>
     <NavigateUrl>https://www.ofstack.com</NavigateUrl>
     <AlternateText>Text_02</AlternateText>
     <KeyWord>two</KeyWord>
     <Impressions>40</Impressions>
     <Aniaml>I'm using adRotator  No.2</Aniaml>
   </Ad>

   <Ad>
     <ImageUrl>cvtxlkw4.gif</ImageUrl>
     <NavigateUrl>https://www.ofstack.com</NavigateUrl>
     <AlternateText>Text_03</AlternateText>
     <KeyWord>three</KeyWord>
     <Impressions>30</Impressions>
     <Aniaml>I'm using adRotator  No.3</Aniaml>
   </Ad>

 </Advertisements>

adRotator.aspx.cs

using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Web;
 using System.Web.UI;
 using System.Web.UI.WebControls;

 public partial class myTest_advertisement : System.Web.UI.Page
 {
     protected void Page_Load(object sender, EventArgs e)
     {

     }
     protected void ad_Created(object sender, AdCreatedEventArgs e)
     {
         if ((string)e.AdProperties["Animal"] != "")
             Label1.Text = (string)e.AdProperties["Aniaml"];
         else
             Label1.Text = "n.a.";
     }
 }

adRotator.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="adRotator.aspx.cs" Inherits="myTest_advertisement" %>

 <!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>Using adRotator</title>
 </head>
 <body>
     <form id="form1" runat="server">
     <div>
       <h1>Adrotator  Control</h1>
        <%--Adrotator file --%>
         <asp:AdRotator ID="AdRotator1" runat="server" 
             Target="_blank"
             AdvertisementFile="ads.xml"
             onAdCreated="ad_Created"/>
             <br />
         Animal:
         <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
     </div> 
     </form>
 </body>
 </html>

1. Reconstruction menu: Extract method (Ctrl+R, Ctrl+M) encapsulates field (Ctrl+R, Ctrl+F)

2. The key word in the dictionary is Animal, which is converted to a string.

(string). AdProperties [" Aniaml "]


Related articles: