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)
{
  if (String.IsNullOrEmpty(e.ImageUrl))
  {
    AdRotator1.Visible = false;
  }
}

Pretty simple, and gets rid of the ugly red ‘X’!

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s