zoukankan
html css js c++ java
FlashAdRotator
我们知道.net自带的AdRotator控件很好用,很多客户都要求做这种轮流的广告,但是有些广告为了效果会采用flash,我在以前的一个项目中就遇到这种情况,所以就写了这个控件,今天把这个控件(
FlashAdRotator)
共享下。(大家对我不要有太高的期望啊,因为我只是很简单的实现了功能)
FlashAdRotator继承自
AdRotator,这样我们就可以省掉很多的事情。
[DefaultProperty(
"
AdvertisementFile
"
)]
[ToolboxData(
"
<{0}:FlashAdRotator runat=server></{0}:FlashAdRotator>
"
)]
public class FlashAdRotator
:
AdRotator
{
private bool isFlash
=
false;
private string imageUrl
=
string
.
Empty;
private string navigateUrl
=
string
.
Empty;
private string alt
=
string
.
Empty;
protected override void Render(HtmlTextWriter writer)
{
//writer.AddAttribute(HtmlTextWriterAttribute.Onclick, "onclickMethod");
if
(isFlash)
{
Flash flash
=
new Flash();
flash
.
ImageUrl
=
this
.
GetUrl(this
.
imageUrl);
flash
.
Width
=
this
.
Width;
flash
.
Height
=
this
.
Height;
flash
.
ID
=
this
.
ID;
flash
.
Style
.
Value
=
this
.
Style
.
Value;
this
.
Controls
.
Add(flash);
flash
.
RenderControl(writer);
}
else
{
base
.
Render(writer);
}
}
protected override void OnAdCreated(AdCreatedEventArgs e)
{
base
.
OnAdCreated(e);
imageUrl
=
e
.
ImageUrl;
navigateUrl
=
e
.
NavigateUrl;
alt
=
e
.
AlternateText;
if
(imageUrl
.
ToLower()
.
EndsWith(
"
.swf
"
))
{
this
.
isFlash
=
true;
}
}
private string GetUrl(string virtualUrl)
{
string applicationPath
=
(HttpRuntime
.
AppDomainAppVirtualPath
.
Length
>
1
)
?
HttpRuntime
.
AppDomainAppVirtualPath
:
String
.
Empty;
if
(
!
string
.
IsNullOrEmpty(virtualUrl))
{
if
(virtualUrl
.
StartsWith(
"
~/
"
))
return
applicationPath
+
virtualUrl
.
Substring(
1
);
else
if
(virtualUrl
.
StartsWith(
"
http://
"
))
return
virtualUrl;
}
return
virtualUrl;
}
}
一般情况下,客户会要求我们做广告点击统计。如果这样的话,我们就要为控件加一个客户端的点击事件。
writer.AddAttribute(HtmlTextWriterAttribute.Onclick, "onclickMethod");
然后写个方法去调用服务器上的广告计数的webservice,利用webservice将结果存入数据库,并进行统计。
查看全文
相关阅读:
大数据学习系列(8)-- WordCount+Block+Split+Shuffle+Map+Reduce技术详解
大数据学习系列(7)-- hadoop集群搭建
.NET的DTO映射工具 AutoMapper
大数据学习系列(6)-- zookeeper集群搭建
大数据学习系列(5)-- 局域网yum仓库搭建
大数据学习系列(4)-- shell编程
大数据学习系列(3)-- 文件权限的操作
大数据学习系列(2)-- IP网段的计算和划分
大数据学习系列(1)-- linux之文件系统结构介绍
MySQL之开启远程连接
原文地址:https://www.cnblogs.com/Linjianyu/p/982085.html
最新文章
Redis和Memcache的对比
使用命令行方式运行 JMeter 脚本
JMeter分布式性能测试
如何解决使用 JMeter 时遇到的问题
CSV Data Set Config参数说明
Jmeter中正则表达式提取器使用详解
如何删除link-local(169.255.0.0) 路由表项
linux配置信息收集
Linux最大打开文件描述符数
centos 7 删除 virbr0 虚拟网卡
热门文章
Linux下的ngnix安装与启动
Nginx rewrite
Nginx 简介与安装
DNS 域名解析
SpringBoot 注解
SpringBoot 多环境配置
SpringBoot 打包
SpringBoot 性能调优
SpringBoot 监控中心
文章集锦
Copyright © 2011-2022 走看看