ASP.Net/Asp Control/Adrotator
Содержание
- 1 asp:adrotator and its xml (VB.net)
- 2 asp:adrotator with a calendar (VB.net)
- 3 Custom asp:AdRotator create event (C#)
- 4 On ad create event for asp:adrotator (VB.net)
- 5 Using a Basic AdRotator Control (VB.net)
- 6 Using a Custom Tag in an AdRotator Control (VB.net)
- 7 Using a Keyword AdRotator Control (VB.net)
asp:adrotator and its xml (VB.net)
<%@ Page Language=VB Debug=true %>
<%@ Import Namespace="System.Data" %>
<script runat=server>
Sub AdCreated_Event(ByVal Sender as Object, _
ByVal E as AdCreatedEventArgs)
lblMessage.Text = "Here is information on the ad " _
& "currently being displayed:<BR>" _
& "<BR>Alternate Text: " & E.AlternateText _
& "<BR>Image URL: " & E.ImageURL _
& "<BR>Navigate URL: " & E.NavigateURL _
& "<BR>Account Name: " _
& E.AdProperties("AccountName").ToString()
End Sub
</SCRIPT>
<HTML>
<HEAD>
<TITLE>AdRotator Control Sample Page</TITLE>
</HEAD>
<BODY >
<form runat="server">
<Font Face="Tahoma">
<asp:adrotator
AdvertisementFile="bannerads.xml"
KeywordFilter="ShowMe"
Target="_blank"
OnAdCreated="AdCreated_Event"
BorderColor="blue"
BorderWidth=3
runat="server"
/>
<BR><BR>
<asp:Label
id="lblMessage"
runat="server"
/>
</Font>
</Form>
</BODY>
</HTML>
<%-- bannerads.xml
<Advertisements>
<Ad>
<ImageUrl>./SampleBanner.gif</ImageUrl>
<NavigateUrl>http://www.google.ru</NavigateUrl>
<AlternateText>Cick me now!</AlternateText>
<Keyword>ShowMe</Keyword>
<Impressions>71</Impressions>
<AccountName>BLR</AccountName>
</Ad>
<Ad>
<ImageUrl>./AnotherSample.gif</ImageUrl>
<NavigateUrl>http://www.nfex.ru</NavigateUrl>
<AlternateText>Go to nfex Site</AlternateText>
<Keyword>ShowMe</Keyword>
<Impressions>70</Impressions>
<AccountName>TVB</AccountName>
</Ad>
<Ad>
<ImageUrl>./DoesNotExist.gif</ImageUrl>
<NavigateUrl>http://www.nfex.ru</NavigateUrl>
<AlternateText>Won"t see me</AlternateText>
<Keyword>DoNotShowMe</Keyword>
<Impressions>2000</Impressions>
<AccountName>SRQ</AccountName>
</Ad>
</Advertisements>
--%>
asp:adrotator with a calendar (VB.net)
<%@ Page Language="vb" %>
<html>
<head>
<title>Rich Control Example</title>
<script runat="server">
Sub Page_Load()
MyAdRotator.KeywordFilter = "Nutshell"
Dim ShortDate As String
ShortDate = MyCalendar.TodaysDate.ToString("D")
MyLabel.Text = "Today is " & ShortDate
End Sub
</script>
</head>
<body>
<h1>Rich Control Example</h1>
<form runat="server">
<asp:table id="MyTable" border="1" cellpadding="5" cellspacing="0" runat="server">
<asp:tablerow runat="server">
<asp:tablecell runat="server">
AdRotator Control:
</asp:tablecell>
<asp:tablecell runat="server">
<asp:adrotator id="MyAdRotator" advertisementfile="bannerads.xml" runat=server/>
</asp:tablecell>
</asp:tablerow>
<asp:tablerow runat="server">
<asp:tablecell runat="server">
Calendar Control:
</asp:tablecell>
<asp:tablecell runat="server">
<asp:calendar id="MyCalendar"
showdayheader="true"
todaydaystyle-backcolor="yellow"
todaydaystyle-forecolor="blue"
runat="server"/>
</asp:tablecell>
</asp:tablerow>
</asp:table>
<asp:label id="MyLabel" runat="server"/>
</form>
</body>
</html>
Custom asp:AdRotator create event (C#)
<%@ Page language="c#" src="AdRotatorTest.aspx.cs" AutoEventWireup="false" Inherits="AdRotatorTest" %>
<HTML>
<body>
<form id="Form1" method="post" runat="server">
<P>
<asp:AdRotator id="Ads" runat="server" Width="468px" Height="60px" AdvertisementFile="MainAds.xml"></asp:AdRotator><BR>
</P>
<P> </P>
<P>
<HR width="100%" SIZE="1">
<P></P>
<P>
<asp:HyperLink id="lnkBanner" runat="server">HyperLink</asp:HyperLink></P>
</form>
</body>
</HTML>
<%--
using System;
using System.Collections;
using System.ruponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
public class AdRotatorTest : System.Web.UI.Page
{
protected System.Web.UI.WebControls.AdRotator Ads;
protected System.Web.UI.WebControls.HyperLink lnkBanner;
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Ads.AdCreated += new System.Web.UI.WebControls.AdCreatedEventHandler(this.Ads_AdCreated);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void Ads_AdCreated(object sender, System.Web.UI.WebControls.AdCreatedEventArgs e)
{
// Synchronize the Hyperlink control.
lnkBanner.NavigateUrl = e.NavigateUrl;
// Syncrhonize the text of the link.
lnkBanner.Text = "Click here for information about our sponsor: ";
lnkBanner.Text += e.AlternateText;
}
}
--%>
On ad create event for asp:adrotator (VB.net)
<%@ Page Language=VB Debug=true %>
<script runat=server>
Sub AdCreated_Event(ByVal Sender as Object, _
ByVal E as AdCreatedEventArgs)
lblMessage.Text = "Here is information on the ad " _
& "currently being displayed:<BR>" _
& "<BR>Alternate Text: " & E.AlternateText _
& "<BR>Image URL: " & E.ImageURL _
& "<BR>Navigate URL: " & E.NavigateURL
End Sub
</SCRIPT>
<HTML>
<HEAD>
<TITLE>Writing Code that Fires when an Ad is created using an AdRotator Control</TITLE>
</HEAD>
<BODY LEFTMARGIN="40">
<form runat="server">
<asp:adrotator
id="ad1"
onadcreated="AdCreated_Event"
advertisementfile="AdRotatorCustom.xml"
target="_blank"
bordercolor="blue"
borderwidth=3
runat="server"
/>
<BR><BR>
<asp:Label
id="lblMessage"
runat="server"
/>
</form>
</BODY>
</HTML>
<%--
<Advertisements>
<Ad>
<ImageUrl>http://www.nfex.ru/style/logo.png</ImageUrl>
<NavigateUrl>http://www.nfex.ru</NavigateUrl>
<AlternateText>Cick me now!</AlternateText>
<Impressions>71</Impressions>
<AccountName>BLR</AccountName>
</Ad>
<Ad>
<ImageUrl>http://www.nfex.ru/style/download.png</ImageUrl>
<NavigateUrl>http://www.microsoft.ru</NavigateUrl>
<AlternateText>Go to Microsoft Site</AlternateText>
<Impressions>70</Impressions>
<AccountName>TVB</AccountName>
</Ad>
</Advertisements>
--%>
Using a Basic AdRotator Control (VB.net)
<%@ Page Language=VB Debug=true %>
<HTML>
<HEAD>
<TITLE>Using a Basic AdRotator Control</TITLE>
</HEAD>
<BODY LEFTMARGIN="40">
<form runat="server">
<asp:adrotator
AdvertisementFile="AdRotatorBasic.xml"
Target="_blank"
BorderColor="blue"
BorderWidth=3
runat="server"
/>
</form>
</BODY>
</HTML>
<%--
<Advertisements>
<Ad>
<ImageUrl>http://www.nfex.ru/style/logo.png</ImageUrl>
<NavigateUrl>http://www.nfex.ru</NavigateUrl>
<AlternateText>Cick me now!</AlternateText>
<Impressions>71</Impressions>
</Ad>
<Ad>
<ImageUrl>http://www.nfex.ru/style/logo.png</ImageUrl>
<NavigateUrl>http://www.microsoft.ru</NavigateUrl>
<AlternateText>Go to Microsoft Site</AlternateText>
<Impressions>70</Impressions>
</Ad>
</Advertisements>
--%>
Using a Custom Tag in an AdRotator Control (VB.net)
<%@ Page Language=VB Debug=true %>
<script runat=server>
Sub AdCreated_Event(ByVal Sender as Object, _
ByVal E as AdCreatedEventArgs)
lblMessage.Text = "Here is the account name for the ad: " _
& E.AdProperties("AccountName").ToString()
End Sub
</SCRIPT>
<HTML>
<HEAD>
<TITLE>Using a Custom Tag in an AdRotator Control</TITLE>
</HEAD>
<BODY LEFTMARGIN="40">
<form runat="server">
<asp:adrotator
id="ad1"
onadcreated="AdCreated_Event"
advertisementfile="AdRotatorCustom.xml"
target="_blank"
bordercolor="blue"
borderwidth=3
runat="server"
/>
<BR><BR>
<asp:Label
id="lblMessage"
runat="server"
/>
</form>
</BODY>
</HTML>
Using a Keyword AdRotator Control (VB.net)
<%@ Page Language=VB Debug=true %>
<HTML>
<HEAD>
<TITLE>Using a Keyword AdRotator Control</TITLE>
</HEAD>
<BODY LEFTMARGIN="40">
<form runat="server">
<asp:adrotator
advertisementfile="AdRotatorKeyword.xml"
keywordfilter="ShowMe"
target="_blank"
bordercolor="blue"
borderwidth=3
runat="server"
/>
</form>
</BODY>
</HTML>
<%--
<Advertisements>
<Ad>
<ImageUrl>http://www.nfex.ru/style/logo.png</ImageUrl>
<NavigateUrl>http://www.nfex.ru</NavigateUrl>
<AlternateText>Cick me now!</AlternateText>
<Keyword>ShowMe</Keyword>
<Impressions>71</Impressions>
</Ad>
<Ad>
<ImageUrl>http://www.nfex.ru/style/download.png</ImageUrl>
<NavigateUrl>http://www.microsoft.ru</NavigateUrl>
<AlternateText>Go to Microsoft Site</AlternateText>
<Keyword>ShowMe</Keyword>
<Impressions>70</Impressions>
</Ad>
<Ad>
<ImageUrl>http://www.nfex.ru/style/download.png</ImageUrl>
<NavigateUrl>http://www.microsoft.ru</NavigateUrl>
<AlternateText>Won"t see me</AlternateText>
<Keyword>DoNotShowMe</Keyword>
<Impressions>2000</Impressions>
</Ad>
</Advertisements>
--%>