Sdílet prostřednictvím


How to: Select Ads in an AdRotator Web Server Control Programmatically

Using the AdRotator Web server control, you can dynamically select ads by creating custom logic within an AdCreated event handler.

To select ads using the AdCreated event

  1. Create an AdCreated event handler for the AdRotator control.

    The second parameter passed in the handler contains a reference to the ad that is being created.

  2. Set the properties of the ad object to specify the image and navigation URLs of the ad to display.

    The following example shows how you can set the ImageUrl, NavigateUrl, and AlternateText properties of the AdCreatedEventArgs control:

    Public Sub AdRotator1_AdCreated(ByVal sender As Object, _
            ByVal e As System.Web.UI.WebControls.AdCreatedEventArgs) _
            Handles AdRotator1.AdCreated
        e.ImageUrl = "images/contoso_ad.gif"
        e.NavigateUrl = "http://www.contoso-ltd.com/"
        e.AlternateText = "Ad for Contoso, Ltd. Web site"
    End Sub
    
    protected void AdRotator1_AdCreated (object sender,
       System.Web.UI.WebControls.AdCreatedEventArgs e)
    {
       e.ImageUrl = "images/contoso_ad.gif";
       e.NavigateUrl = "http://www.contoso-ltd.com/";
       e.AlternateText = "Ad for Contoso, Ltd Web site";
    }
    

See Also

Reference

AdRotator Web Server Control Overview