DotNetStories
In this second post of presenting the basic web server controls in ASP.Net we will look into the Adrotator control. You can find the first post here.
I think that people who begin now with ASP.Net will find these posts useful.
We can use the Adrotator control and to serve up random
banners in our web site.
I will use a hands-on an
example with C# version.I will use an XML file that will
serve as the source for my banners.
The
AdRotator was included in ASP.Net 2.0 version.
I will be using VS 2010 Ultimate edition to create a
simple asp.net application.
1) Launch Visual
Studio 2010/2008/2005 (or express editions).
2)
Create a new website and choose an approriate
name.
3) From your toolbox just drag and drop an
AdRotator Control in the
Default.aspx page
5) Click on your project
from the Solution explorer and create an
Images folder
6) Place your random images
in the folder above
7) Add a new item to your
site. IName it “advs.xml”. Place it in the
App_Data special folder that is already created in
your project structure.
8) Copy and paste the
following XML code inside the “advs.xml” file.
<?xml version=”1.0″ encoding=”utf-8″ ?>
<Advertisements
xmlns=”http://schemas.microsoft.com/AspNet/AdRotator-Schedule-File”>
</Advertisements>
<Ad>
<ImageUrl>~/images/ajax-logo.gif</ImageUrl>
<NavigateUrl>http://www.asp.net/ajax/</NavigateUrl>
<AlternateText>ASP.NET
AJAX is a free framework for quickly creating efficient
and interactive Web applications that work across all
popular browsers</AlternateText>
<Keyword>asp.net
ajax</Keyword>
<Impressions>100</Impressions>
</Ad>
<Ad>
<ImageUrl>~/images/asp-logo.png</ImageUrl>
<NavigateUrl>http://www.asp.net</NavigateUrl>
<AlternateText>ASP.NET
is a free technology that allows anyone to create a modern
web site</AlternateText>
<Keyword>Asp.Net</Keyword>
<Impressions>150</Impressions>
</Ad>
<Ad>
<ImageUrl>~/images/NET-logo.png</ImageUrl>
<NavigateUrl>http://www.microsoft.com/NET/</NavigateUrl>
<AlternateText>The
.NET Framework is Microsoft’s comprehensive and consistent
programming model for building applications
</AlternateText>
<Keyword>.NET</Keyword>
<Impressions>250</Impressions>
</Ad>
</Advertisements>
Enable AutoPostBack property for this control.By
clicking on this control in the
Default.aspx.cs,
You will be presented
with the event handling routine for the standard
event(SelectedIndexChanged).
Now create a new .aspx page and make it the Start page.Name
it as you want.
Place a new
AdRotator control in the newly created page.
Now
we must have a datasource control that points to the
database we created and tie this datasource control with the
rotator control.
Click on the little arrow in the
rotator control and choose New Data Source, choose
database from the window and then from the
Configure DataSource window, select the
banner database and click
Next.
Then select the ads table and
select all the fields from the table. Test the query and
click Finish.
Run your application and see
the ads to apper now from the database.
You can
email me if you want the source code or leave a comment.
Hope
it helps!!!!