Random rotation of advertisements is made very easy in Visual Studio. This tutorial shows how to implement this control, and also a way of monitoring the number of clicks each ad receives.
This tutorial uses graphics to display clickable advertisements.
Create New Folder in Solution Explorer for images. Copy to this folder existing images to be used as advertisements.
Then create an XML file to list the ads:
This tutorial uses graphics to display clickable advertisements.
Create New Folder in Solution Explorer for images. Copy to this folder existing images to be used as advertisements.
Then create an XML file to list the ads:
Change NavigateUrl in the XML file (Sample.ads):
Now add another XML file - AdResponse.xml - to count the number of clicks.
protected void Page_Load(object sender, EventArgs e) { String adName = Request.QueryString["ad"]; }String redirect = Request.QueryString["target"]; if (adName == null | redirect == null) redirect = "Default.aspx"; System.Xml.XmlDocument doc = new System.Xml.XmlDocument(); String docPath = @"~/App_Data/AdResponses.xml"; doc.Load(Server.MapPath(docPath)); System.Xml.XmlNode root = doc.DocumentElement; System.Xml.XmlNode adNode = root.SelectSingleNode( @"descendant::ad[@adname='" + adName + "']"); if (adNode != null) { int ctr = }int.Parse(adNode.Attributes["hitCount"].Value); ctr += 1; System.Xml.XmlNode newAdNode = adNode.CloneNode(false); newAdNode.Attributes["hitCount"].Value = ctr.ToString(); root.ReplaceChild(newAdNode, adNode); doc.Save(Server.MapPath(docPath)); Response.Redirect(redirect); |
Add XmlDataSource from the toolbox and choose AdResponses.xml (containing click data) as Data Source.
Also add GridView from toolbox and choose the Data Source. The code should be something like this:
Rotator Control for C#.NET application
ReplyDelete