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将结果存入数据库,并进行统计。
查看全文
相关阅读:
Google File System(中文翻译)
Hadoop学习之路一 Single Node Setup
大数据建模比赛--金融市场板块划分和轮动规律研究.
华中建模-人脸识别
计算循环队列的元素个数
低价租用高性能GPU进行深度学习
vscode+PyQt+QtDesigner
mask_rcnn(Keras+TensorFlow)环境搭建_新手向(毕业设计使用,亲测可用)
博客园美化
Task1 赛题理解
原文地址:https://www.cnblogs.com/Linjianyu/p/982085.html
最新文章
PYTHON PYQUERY 基本用法
一次完整的HTTP请求过程
如何使用FireBug和FireFinder
myslq单表查询
java中list、set、map的遍历方法
生产验证码的代码
如何快速发现软件的bug
Myeclipse打开后报错Could not create the view: An unexpected exception was thrown.
Javabean学习纪要
使用junit测试函数时报错“unrooted Tests” “Method 'initializationError' not found.Opening the test class”
热门文章
JavaBean规范
web开发中请求转发和重定向的区别
Ubuntu下安装IntellliJIDEA时提示ERROR: cannot start IntelliJ IDEA. No JDK found to run IDEA. Please validate either JDK_HOME
DOS中的tree命令
深入理解Linux修改hostname
CentOS6.6安装wine
163yum源的配置
Required :libstdc++.so.6: (GLIBCXX_3.4.14)
datanode出现自动关闭状况
MapReduce:超大机群上的简单数据处理
Copyright © 2011-2022 走看看