溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

ASP.NET中如何使用廣告控件

發(fā)布時間:2021-07-16 13:57:30 來源:億速云 閱讀:109 作者:Leah 欄目:開發(fā)技術(shù)

ASP.NET中如何使用廣告控件,相信很多沒有經(jīng)驗(yàn)的人對此束手無策,為此本文總結(jié)了問題出現(xiàn)的原因和解決方法,通過這篇文章希望你能解決這個問題。

ads.xml

復(fù)制代碼 

<?xml version="1.0" encoding="utf-8"?>
  <!--廣告文件是一個XML文件-->
 <Advertisements>
   <Ad>
     <ImageUrl>4rwbgzby.gif</ImageUrl>
     <NavigateUrl>https://www.jb51.net</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.jb51.net</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.jb51.net</NavigateUrl>
     <AlternateText>Text_03</AlternateText>
     <KeyWord>three</KeyWord>
     <Impressions>30</Impressions>
     <Aniaml>I'm using adRotator  No.3</Aniaml>
   </Ad>

 </Advertisements>


adRotator.aspx.cs

復(fù)制代碼 代碼如下:


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

復(fù)制代碼 代碼如下:


<%@ 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>
       <h2>Adrotator  Control</h2>
        <%--Adrotator文件--%>
         <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、重構(gòu)菜單:提取方法(Ctrl+R,Ctrl+M)    封裝字段(Ctrl+R,Ctrl+F)   

2、字典中的關(guān)鍵字是Animal,  該值轉(zhuǎn)化為字符串,

     (string).AdProperties["Aniaml"]

看完上述內(nèi)容,你們掌握ASP.NET中如何使用廣告控件的方法了嗎?如果還想學(xué)到更多技能或想了解更多相關(guān)內(nèi)容,歡迎關(guān)注億速云行業(yè)資訊頻道,感謝各位的閱讀!

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI