Someone asked me in Glasgow how they could take advantage of ASP.NET AJAX on their site but still maintain their advertising banners which refresh on postback. Fewer postbacks = fewer refreshes = fewer payments (I was surprised to learn that revenue was generated per view rather than per click). The advertising company typically provides a line of script something like:
<img src="http://mikeo.co.uk/randomadvert.jpg" alt="Advert" />');
And in the case in question, you passed a random number to the script and it would return an advert to you (something a little more complex that just an image but you get the idea). Problem is you can't just wrap this in an UpdatePanel and expect it to work as "rendering script or markup directly...such as by calling the Write(string) method" is not supported. Some other technique is required.
Well I wrestled with a few but all of them failed due to cross-domain security restrictions on the browser as the script I'm trying to download comes from a domain owned by the advertising company. More head scratching...
I now have a string representing the markup for the advert and I can return this as a string to the client. On the client side, I take the result (the markup string) and simply set the innerHTML of a suitable <div> tag to host the advert. And voila - it works. There are a few problems however:
- The advertising company now sees all requests for my customers as coming from my server. As they're paying per view, I'd assume they have some sort of anti-fraud mechanism to prevent some unscrupulous person just pinging the script repeatedly. That's not exactly how we're going to appear to them...
- The mechanism is less efficient as there are extra web requests involved
- The mechanism puts a greater load on my servers as each page request now creates an extra web service call (this may be offset by some of the AJAX benefits though)
- Stripping the response to arrive at the markup is a bit hacky
- And probably some others you'll now point out to me... 🙂