Some days, I wonder about the people who write the ASP.NET controls…
Today, I was implementing the AdRotator control on one of our main pages. The control needed to do the following… display an image if there was something to display, but if not, don’t display ANYTHING.
Unfortunately, what the control does if there is nothing to display is set the image source to an empty string. On Internet Explorer 8, this produces the following lovely result:
Doh! That’s not what I wanted!
Fortunately, there is a quick answer. The AdRotator control has an AdCreated event. By assigning a bit of code to it, one can check if the ImageUrl property is blank. At that point, it’s very easy to hide the control.
Here’s the code:
protected void AdRotator1_AdCreated(object sender, AdCreatedEventArgs e)
AdRotator1.Visible = false;
Pretty simple, and gets rid of the ugly red ‘X’!