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将结果存入数据库,并进行统计。
查看全文
相关阅读:
内部类
三大修饰符:static、final、abstract
面向对象三大特性
类和方法
Vue-创建工程+element UI
xshell连接虚拟机较慢问题 -----已解决
Hbase配置
Hive的安装配置
Hive内容+配置
Redis全局命令
原文地址:https://www.cnblogs.com/Linjianyu/p/982085.html
最新文章
C#调用java的jar文件的方法(转)
silverlight MVC System.Security.SecurityException: 安全性错误。
刷新后 页面 保持滚动条位置
ASP.NET Session丢失原因和应对策略
HTML乱码问题
java.lang.ClassNotFoundException: org.springframework.web.filter.CharacterEncodingFilter
1064
mybatis中运行报错java.lang.ExceptionInInitializerError
org.apache.ibatis.binding.BindingException: Type interface com.jy.dao.UserDao is not known to the MapperRegistry.
[ERROR] 1 problem was encountered while building the effective settings
热门文章
Springboot打包发布时boot-01-1.0-SNAPSHOT.jar中没有主清单属性
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
springboot集成logback
logback日志的集成
Lamda表达式
图片下载的两种方式Thread和Callable
多线程第一天
集合
包装类
异常
Copyright © 2011-2022 走看看