CODEDIGEST
Home » Articles
Search
 

Technologies
 

Sponsored links
 

CodeDigest Navigation
 

Technology News
No News Feeds available at this time.
 

Community News
No News Feeds available at this time.
 
Using ADRotator Control in ASP.Net - Part 2

By Satheesh Babu
Posted On Jul 17,2010
Article Rating:
Be first to rate
this article.
No of Comments: 5
Category: ASP.Net
Print this article.

Using AdRotator Control in ASP.Net - Part 2

Tracking Ad clicks

 

In Part 1 of this article series, we have seen some of the basic usages of AdRotator control in an ASP.Net page. In Part 2, we will see how to track an advertisement performance by adding a hit counter for each advertisement. To understand this, we will use database instead of XML file to render the ads with AdRotator control.

 

Tracking Advertisement Using AdRotator control

To track the advertisement in terms of number of clicks or hits, we need to pass the user to the destination page (ad’s landing page) through a proxy webpage or an HttpHandler. This proxy can then update your click into the database and will redirect the user to target page.

Below is the database design which we can use.

 

Building a Simple Ad management system in ASP.Net using AdRotator control

 

Drag an AdRotator control and a SqlDataSource control from your visual studio toolbar. Bind the AdRotator control through DataSourceID property after configuring the datasource control.

 

As i said before, we need to create a proxy which can record the clicks and redirects the user to target page. We will use HttpHandler to do this. Include a new HttpHandler to your solution through “Add new Item..” dialog box, name it as AdHandler.ashx.

 

Refer the below code,

 

public class AdHandler : IHttpHandler

    {

        public void ProcessRequest(HttpContext context)

        {

            string url = context.Request.QueryString["AdUrl"];

            try

            {

                AddHit(url);

            }

            catch

            {

            }

            finally

            {

                context.Response.Redirect(url);

            }

        }

        public int AddHit(string url)

        {

            SqlConnection con = new
SqlConnection(ConfigurationManager.ConnectionStrings
["ConnectionString"].ConnectionString);

            con.Open();

            SqlCommand com = new SqlCommand("AddHit", con);

            com.CommandType = System.Data.CommandType.StoredProcedure;

            com.Parameters.Add(new SqlParameter("@url",url));

            int res = com.ExecuteNonQuery();

            con.Close();

            return res;

        }

        public bool IsReusable

        {

            get

            {

                return false;

            }

        }

    }

SP

ALTER PROCEDURE dbo.AddHit

       (

       @url varchar(200)

       )     

AS

       DECLARE @ADID INT

      

       SELECT  @ADID = AdID from ADs where NavigateUrl = @url

      

       IF exists (Select ADID FROM AdHits where ADID = @ADID)

              UPDATE ADHits SET Hits = Hits+1 where ADID = @ADID

       ELSE  

       INSERT INTO ADHits values (@ADID,1)

RETURN

 

This HttpHanlder will accept the ad’s landing page (or NavigateUrl) as a querystring parameter to record the click into our database. Once it is recorded, the user will be redirected to the target ad’s page.

Now, we need to make the AdRotator control to use this proxy handler to redirect the user instead of passing them directly.

 

Well, this can be done by 2 ways.

1.      By AdCreated event

The AdCreated event will expose the advertisements NavigateUrl, ImageUrl, AlternateText properties which can be changed. You can use this event to pass the user through the proxy handler. Refer below,

ASPX

<asp:AdRotator ID="AdRotator1" runat="server" DataSourceID="SqlDataSource1"

            onadcreated="AdRotator1_AdCreated" />

    <asp:SqlDataSource ID="SqlDataSource1" runat="server"

        ConnectionString="<%$ ConnectionStrings:ConnectionString %>"

        SelectCommand="SELECT * FROM [Ads]"></asp:SqlDataSource>

 

CodeBehind

protected void AdRotator1_AdCreated(object sender, AdCreatedEventArgs e)

        {

            e.NavigateUrl = "AdHandler.ashx?AdUrl=" + e.NavigateUrl;

        }

 

2.      By Ad XML or Database table

When configuring the NavigateUrl property of the ad, you can use the proxy handler. Something like below,

<Ad>

    <ImageUrl>~/img/AccordionPanel.jpg</ImageUrl>

    <NavigateUrl>      AdHandler.ashx?AdUrl=http://www.codedigest.com/Articles/jQuery/335_Creating_Accordion
_Panel_using_jQuery_in_ASPNet_%e2%80%93_Part_1.aspx

    </NavigateUrl>

    <AlternateText>

      Creating Accordion Panel using jQuery in ASP.Net

    </AlternateText>   

  </Ad>

 

We can now get the report of hits/clicks of the ads from the ADHits table.

 




Change Advertisements without page refresh in AdRotator control

One disadvantage of AdRotator control is, it will change the ad only if user refreshes the page or for the next page refresh. It will be really good if we can change the ads at regular intervals even if the user did not refresh the page. This can be done by using the ASP.Net AJAX update panel control and Timer control.

Read below code snippet which will help us to implement the same.

Change Advertisement in AdRotator without Page Refresh at Regular Interval

 

Downloads

Download Source 

Conclusion

Creating an advertisement management system ourselves is complicated and time consuming task. Most of the time, we can use the AdRotator control in ASP.Net to build a basic ad management system that can satisfy our needs.

Download the source attached with this article to see it in action.

Happy Coding!!

 

Similar Articles
You can contribute to CodeDiget.Com:
Donate to CodeDigest.com
Article Feedback
Comments
Opera 9.00 Windows
Opera 9.00 Windows XPThe teeth whitening medtohs industry is now richer and richer. And this is because the demands have grown greatly in the past few years. Due to today's alimentation, surplus of tobacco and coffee more and more people need teeth bleaching medtohs. Every body whishes to truly have a beautiful white smile. And there are many of techniques to accomplish that. Here are some good teeth bleaching tips that one may fallow: - there are several teeth whitening strategies that you can use in the home nevertheless the best results you can get are when you are under dentist guidance. Teeth bleaching can be used at home but I would advise you to complete it at your dentist position, because dentist watched procedures are 90 % successful and the outcome have a tendency to go longer. - Rather than finding yellow, your teeth could easily get stained. This is also bad looking. It's very annoying to have to full cover up your look since you have bad teeth. This spots are often due to drinks like espresso, tea, red wine or several black colored ingredients. This awful spots can be removed with cosmetic dentistry procedures. - If you'll go to a dentist he will surely know what to accomplish and what to suggest. Teeth are usually used 3 by dentists whitening practices. This could be bleaching your teeth in-office, bleaching your teeth with laser and bleaching your teeth in the home. If all the dentists guidelines are strictly followed all of this medtohs may have great benefits. - Another thing that you need to to before using any teeth whitening techniques is always to always check your dentists knowledge and past results. It's good to choose only professionals for the mouth. - With regards to the length of time you may spend bleaching your teeth will become brighter and brighter. Ask your dentist to show you some taste cards where you can easily see how your teeth will look like. This cards are extremely similar with ones employed for selecting hair paints. Pick the one yo http://sikvrmdkcw.com [url=http://ehglwr.com]ehglwr[/url] [link=http://nfqcyicv.com]nfqcyicv[/link]
Internet Explorer 7.
Internet Explorer 7.0 Windows XPHere's an excerpt from my short<a href="http://rmxrnzezpu.com"> alrcite</a> The Mistress: Victim or Culprit?There are quite a few over the internet dating web pages for married individuals readily available by means of the whole net. Most of them provide zero cost registration to turn into a member. You can are a member by means of these cost-free registrations and can commence your quest on what you're up to. must you ends up finds practically nothing then you can undoubtedly merely cancel the registration. Some of the web pages which can be considered as the most beneficial makes it possible for you to search and even tends to make you get contacted when utilizing opposite person to grow to be prospective partner. All you will need to do is undoubtedly you have to make your profile and start your quest.Clare and I hardly speak at present. It really is just organization, childcare, dollars passing your youngsters back and forth. She looks considerably older than she did prior to the divorce. She's lost her appears. I am considerably happier with Tanya. Our really like life is nonetheless decent even even though the intensity has worn off. I would not truly say I chose to have divorced. Items just ended up this way due to the fact my spouse wanted significantly more young children than I did. I assume most married males will take a lover when the opportunity happens to be honest. It does not imply we all want to have divorced although. I most likely would often be married to Clare if she hadn't insisted on developing a third baby. But it's the way it went. Two youngsters marriage 3 kids divorce. I do not suppose I am the only bloke to get fed up with the domestic life along with a residence packed with children. The issue is most males, due to the decision from a residence filled with children's toys as effectively as a flat using a attractive, out there woman inside it will choose the sexy woman. We're largely not worthy of monogamy and raising children for my component. It is only the wa
Internet Explorer 7.
Internet Explorer 7.0 Windows XPFrom the word itself, it's pelceftry clear that the water heater warms or heats water. We cannot deny the fact we want warm water. We are in need of it for our soups and coffee. We need hot water for our baths (we dont desire to freeze to death with cold water). We truly need it to wash our clothes in, to clean our vehicles with and to warm our pools. We want it for a calming soak in the tub following a hard trip to work. Undoubtedly, there are numerous items that require the utilization of hot water and the simplest way to own hot water is by utilizing water heaters. The marketplace at this time provides various sorts and kinds of hot water heater to accommodate everyones wants. Currently there are four types and you can pick the one that you think would best suit your financial allowance and your needs. One that is gaining popularity is the solar water heater. The solar water heater depends upon the suns power to heat up your water. Your geographical area is very important to take into account when buying this kind of water heater. It is important that you get amply supply of sunlight to be able to maximize the utilization of your heater. This could actually come in handy if you reside in a location with a the sunshine. These don't come at a cheap price though. A solar water heater would have been a good option for after all; the suns power is completely free, if you're considering a long term investment, the one that can certainly save you on fees. A back-up water heater is just needed by you though in case you'll be experiencing times when there is number sun. Perhaps the earliest method of heating water could be utilizing the range but in these times you will find ranges with built in water jackets. If your range is of all of the time, you could have free heated water with this particular. This really is also an efficient water heater. Electric water heaters are utilized by most people as a back-up. To it might be a bit expensive to use because of the http://omeazl.com [url=http://dxiwxir.com]dxiwxir[/url] [link=http://onbfhm.com]onbfhm[/link]
Firefox 4.0 Arch L
Firefox 4.0 Arch LinuxIt is the same as purchasing<a href="http://ppilpckux.com"> aatcul</a> estate. The 3 most important factors to keep in mind are place, location and place.If you will only be over-nighting in Bangkok, you may just want to stay at a hotel near the airport. Visitors can be horrendous in Bangkok, and you dont want to threat missing your flight.If you are like me and want to get out during your remain in Bangkok, staying in the Sukhumvit Road location is the location to be.I only remain in Bangkok when I totally have to but when I do I look for hotels in the Sukhumvit and Soi 4 location. There are a few factors for undertaking this:- It is correct in the heart of the action. Bars are inside walking distance and rates for the hotel are affordable.- There are quite a few restaurants inside a 5 minute walk. I can get Thai, American, Italian, and several far more European and Asian dishes simply.- If I do require to get a taxi, I can open the front door of the hotel and take about 3 steps and get a cab.- When it is time for me to depart and head for the airport, I get a taxi and a brief jaunt across Sukhumvit and we are on the tollway. You dont want to get stuck in Bangkok traffic when you want to catch a flight.- Even even though I speak reasonable Thai, it is good that most of the stores and shops in the region speak a small bit of English. It saves time and makes the purchasing less complicated.- Speaking of buying, Sukhumvit is a mecca of street vendors. Sharpen your negotiating capabilities and get all of your souvenirs at dirt cheap rates.- Free of charge breakfast. I typically stay at the Majestic Suites Hotel on Sukhumvit between Soi 4 and Soi six (closer to Soi four) and they have a simple totally free breakfast.- I can book on-line. There are numerous locations to book hotels in this region making use of online booking which saves me time and income.- Comparatively secure. There is a police box correct on the corner of Sukhumvit and Soi four if you require aid from t
Have you found a way
Have you found a way to do this within CRM 2011 ? I'd like to inmlemept a list of attachments with clickable URLs through a SSRS report (dashboard), but I'haven't found a way to provide the base64 decoding required to open the attachment directly (that is, not going through opening the note first).