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将结果存入数据库,并进行统计。
查看全文
相关阅读:
线程和进程
Map和Collection
数组
泛型
堆和栈
Java的三大特性
Log日志
关系运算
switch
main 及Scanner
原文地址:https://www.cnblogs.com/Linjianyu/p/982085.html
最新文章
$_SERVER
鼠标模拟点击a标签
MYSQL基础--学习笔记
MYSQL 查询出最大/最小值所在的记录
sublime text 也能矩形选择
【转】上海集体户口开户籍证明
Jsp参数传递
jqGrid模板
js控制在页面显示时间,每秒更新一次
jquery随笔
热门文章
jqGrid获取一行数据的方法
Java保留两位小数
关于Java-web里面properties的路径问题
2013总结
微信开发--入门(二)
微信开发--入门(一)
20130808
java 垃圾回收知识点
面试记-(1)
JQuery
Copyright © 2011-2022 走看看