Attention: We are retiring the ASP.NET Community Blogs. Learn more >

Adding advert rotator to your web app

I am going to show you how you can easy add cool advertisement banner rotator to your web applications, because in our days most important for your web pages to be successful is to "catch" the eye of your visitors and make them stay as long as possible. Ok first i will start from aspx code.

Drag and drop Timer control (by the way I am using ajax control toolkit which is offered for free from codeplex and you can download it from here ).

<asp:Timer ID="Timer1" runat="server" Interval="1000" OnTick="Timer1_Tick" />

for time interval you can set whatever value you like in miliseconds (this is the changing image speed of your adds). OnTick, this is the place where I am going to use the tick event of the timer control.

<asp:UpdatePanel ID="UpdatePanel1" runat="server">

<Triggers>

<asp:AsyncPostBackTrigger ControlID="Timer1" />

</Triggers>

<ContentTemplate>

<asp:Image ID="img" runat="server" ImageUrl="~/Images/1.gif" />

</ContentTemplate>

</asp:UpdatePanel>

 

Second place an update panel and set the triger ControlID to Timer1 which is the ID of our timer control, and the Content Template where you can place whatever control you like (I've used just simple image).

Now, its time to work around the code behind and to "connect" our images with the timer ticking.

Protected Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick Dim ran As Integer = New Random().Next(1, 9)

img.ImageUrl = "~/Images/" & ran & ".gif"

End Sub

I am generating random number from 1 to 9 when the timers time runs out and setting the image url attribute to an image name which by the way I've placed in folder "Images" and named them 1.gif, 2.gif ...9.gif.

Well thats it ....simple.

 

Have fun

No Comments