如何:以编程方式在 AdRotator Web 服务器控件中选择广告

来源:互联网 发布:手机淘宝秒杀要刷新吗 编辑:程序博客网 时间:2024/05/02 00:09

使用 AdRotator Web 服务器控件,可以通过在 AdCreated 事件处理程序中创建自定义逻辑来动态选择广告。

使用 AdCreated 事件选择广告

  1. AdRotator 控件创建 AdCreated 事件处理程序。

    在该处理程序中传递的第二个参数包含对要创建的广告的引用。

  2. 设置广告对象的属性,以指定要显示的广告的图像和定位 URL。

    下面的示例演示如何设置 AdCreatedEventArgs 控件的 ImageUrl、NavigateUrl 和 AlternateText 属性:

    Visual Basic
    复制代码
    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

     

    C#
    复制代码
    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";}
 
原创粉丝点击