Asp.Net2.0页面通过ICallbackEventHandler接口实现Ajax
2009-01-08 14:42
399 查看
1.页面继承ICallbackEventHandler接口。
2.编写服务器端代码:
#region ICallbackEventHandler
string result = string.Empty;
string ICallbackEventHandler.GetCallbackResult()
{
return result;
}
void ICallbackEventHandler.RaiseCallbackEvent(string eventArgument)
{
string aid = "";//Ads id
Regex r;
Match m;
if (eventArgument.Contains("method=getDetail"))
{
r = new Regex("(?<=(aid=))\\w*");
m = r.Match(eventArgument);
if (m.Success)
aid = m.Value;
if (aid != string.Empty)
{
result = GetAdDetail(aid);
}
}
}
/// <summary>
/// 获得详情
/// </summary>
/// <param name="aid"></param>
/// <returns></returns>
private string GetAdDetail(string aid)
{
string r = string.Empty;
IAdColumn ad=BkServices.PromotionService.GetAdColumn(aid);
if (ad != null)
{
if (ad.AdColumnType == AdvertisingType.Infomation_Wanted)
{
return string.Format("{0}&{1}", ad.Name, ad.Content);
}
else if (ad.AdColumnType == AdvertisingType.Infomation_Offering)
{
}
}
return r;
}
#endregion
3.编写客户端代码:
<script type="text/javascript">
var docEle = function()
{
return document.getElementById(arguments[0]) || false;
}
function openNewDiv(_id,detail)
{
//获得参数
var items=detail.toString().split("&");
var m = "mask";
if (docEle(_id)) document.body.removeChild(docEle(_id));
if (docEle(m)) document.body.removeChild(docEle(m));
//mask遮罩层
var newMask = document.createElement("div");
newMask.id = m;
newMask.style.position = "absolute";
newMask.style.zIndex = "1";
_scrollWidth = Math.max(document.body.scrollWidth,document.documentElement.scrollWidth);
_scrollHeight = Math.max(window.screen.availHeight,document.documentElement.scrollHeight);
newMask.style.width = _scrollWidth + "px";
newMask.style.height = _scrollHeight + "px";
newMask.style.top = "0px";
newMask.style.left = "0px";
newMask.style.background = "#999999";
newMask.style.filter = "alpha(opacity=40)";
newMask.style.opacity = "0.40";
document.body.appendChild(newMask);
//新弹出层
var newDiv = document.createElement("div");
newDiv.id = _id;
newDiv.style.position = "absolute";
newDiv.style.zIndex = "9999";
newDiv.className="";
newDivWidth = 562;
newDivHeight = 260;
newDiv.style.top = (document.body.scrollTop + document.body.clientHeight/2 - newDivHeight/2) + "px";
newDiv.style.left = (document.body.scrollLeft + document.body.clientWidth/2 - newDivWidth/2) + "px";
var detail="<div class='pay_layer'><h1>详细信息</h1><h6 class='mt10 yellow_Bg'><font class='red'>信息标题:</font>"+items[0]+"</h6><h6 class='mt10 yellow_Bg'><font class='red'>详细介绍:</font><h5 class='f14 fnormal'>"+items[1]+"</h5></h6><h2><input type='button' value='确 认' style='margin:0 0 0 0; width:60px;' onclick='newDiv.closeMask()'/></h2></div>";
newDiv.innerHTML = detail;
document.body.appendChild(newDiv);
//弹出层滚动居中
function newDivCenter()
{
newDiv.style.top = (document.body.scrollTop + document.body.clientHeight/2 - newDivHeight/2) + "px";
newDiv.style.left = (document.body.scrollLeft + document.body.clientWidth/2 - newDivWidth/2) + "px";
}
if(document.all)
{
window.attachEvent("onscroll",newDivCenter);
}
else
{
window.addEventListener('scroll',newDivCenter,false);
}
//关闭新图层和mask遮罩层
newDiv.closeMask = function()
{
if(document.all)
{
window.detachEvent("onscroll",newDivCenter);
}
else
{
window.removeEventListener('scroll',newDivCenter,false);
}
document.body.removeChild(docEle(_id));
document.body.removeChild(docEle(m));
return false;
}
newDiv.appendChild(newA);
}
function closeWin()
{
alert();
if(document.all)
{
window.detachEvent("onscroll",newDivCenter);
}
else
{
window.removeEventListener('scroll',newDivCenter,false);
}
document.body.removeChild(docEle('_id'));
document.body.removeChild(docEle('m'));
return false;
}
</script>
<script type="text/javascript" language="javascript">
//ajax显示详情
function getDetail(aid)
{
{
var param="method=getDetail&aid="+aid;
<%=Page.ClientScript.GetCallbackEventReference(this,"param", "setDetail", "")%>;
}
}
function setDetail(result,context)
{
openNewDiv('newDiv',result);
return false;
}
</script>
2.编写服务器端代码:
#region ICallbackEventHandler
string result = string.Empty;
string ICallbackEventHandler.GetCallbackResult()
{
return result;
}
void ICallbackEventHandler.RaiseCallbackEvent(string eventArgument)
{
string aid = "";//Ads id
Regex r;
Match m;
if (eventArgument.Contains("method=getDetail"))
{
r = new Regex("(?<=(aid=))\\w*");
m = r.Match(eventArgument);
if (m.Success)
aid = m.Value;
if (aid != string.Empty)
{
result = GetAdDetail(aid);
}
}
}
/// <summary>
/// 获得详情
/// </summary>
/// <param name="aid"></param>
/// <returns></returns>
private string GetAdDetail(string aid)
{
string r = string.Empty;
IAdColumn ad=BkServices.PromotionService.GetAdColumn(aid);
if (ad != null)
{
if (ad.AdColumnType == AdvertisingType.Infomation_Wanted)
{
return string.Format("{0}&{1}", ad.Name, ad.Content);
}
else if (ad.AdColumnType == AdvertisingType.Infomation_Offering)
{
}
}
return r;
}
#endregion
3.编写客户端代码:
<script type="text/javascript">
var docEle = function()
{
return document.getElementById(arguments[0]) || false;
}
function openNewDiv(_id,detail)
{
//获得参数
var items=detail.toString().split("&");
var m = "mask";
if (docEle(_id)) document.body.removeChild(docEle(_id));
if (docEle(m)) document.body.removeChild(docEle(m));
//mask遮罩层
var newMask = document.createElement("div");
newMask.id = m;
newMask.style.position = "absolute";
newMask.style.zIndex = "1";
_scrollWidth = Math.max(document.body.scrollWidth,document.documentElement.scrollWidth);
_scrollHeight = Math.max(window.screen.availHeight,document.documentElement.scrollHeight);
newMask.style.width = _scrollWidth + "px";
newMask.style.height = _scrollHeight + "px";
newMask.style.top = "0px";
newMask.style.left = "0px";
newMask.style.background = "#999999";
newMask.style.filter = "alpha(opacity=40)";
newMask.style.opacity = "0.40";
document.body.appendChild(newMask);
//新弹出层
var newDiv = document.createElement("div");
newDiv.id = _id;
newDiv.style.position = "absolute";
newDiv.style.zIndex = "9999";
newDiv.className="";
newDivWidth = 562;
newDivHeight = 260;
newDiv.style.top = (document.body.scrollTop + document.body.clientHeight/2 - newDivHeight/2) + "px";
newDiv.style.left = (document.body.scrollLeft + document.body.clientWidth/2 - newDivWidth/2) + "px";
var detail="<div class='pay_layer'><h1>详细信息</h1><h6 class='mt10 yellow_Bg'><font class='red'>信息标题:</font>"+items[0]+"</h6><h6 class='mt10 yellow_Bg'><font class='red'>详细介绍:</font><h5 class='f14 fnormal'>"+items[1]+"</h5></h6><h2><input type='button' value='确 认' style='margin:0 0 0 0; width:60px;' onclick='newDiv.closeMask()'/></h2></div>";
newDiv.innerHTML = detail;
document.body.appendChild(newDiv);
//弹出层滚动居中
function newDivCenter()
{
newDiv.style.top = (document.body.scrollTop + document.body.clientHeight/2 - newDivHeight/2) + "px";
newDiv.style.left = (document.body.scrollLeft + document.body.clientWidth/2 - newDivWidth/2) + "px";
}
if(document.all)
{
window.attachEvent("onscroll",newDivCenter);
}
else
{
window.addEventListener('scroll',newDivCenter,false);
}
//关闭新图层和mask遮罩层
newDiv.closeMask = function()
{
if(document.all)
{
window.detachEvent("onscroll",newDivCenter);
}
else
{
window.removeEventListener('scroll',newDivCenter,false);
}
document.body.removeChild(docEle(_id));
document.body.removeChild(docEle(m));
return false;
}
newDiv.appendChild(newA);
}
function closeWin()
{
alert();
if(document.all)
{
window.detachEvent("onscroll",newDivCenter);
}
else
{
window.removeEventListener('scroll',newDivCenter,false);
}
document.body.removeChild(docEle('_id'));
document.body.removeChild(docEle('m'));
return false;
}
</script>
<script type="text/javascript" language="javascript">
//ajax显示详情
function getDetail(aid)
{
{
var param="method=getDetail&aid="+aid;
<%=Page.ClientScript.GetCallbackEventReference(this,"param", "setDetail", "")%>;
}
}
function setDetail(result,context)
{
openNewDiv('newDiv',result);
return false;
}
</script>
相关文章推荐
- 利用ICallbackEventHandler接口实现Ajax效果
- c# 通过ICallbackEventHandler 实现页面“无刷新”
- c#通过ICallbackEventHandler接口实现回调
- c# 通过ICallbackEventHandler 实现页面无刷新
- 页面加载后检查用户登录状态,通过ajax实现
- 通过nginx实现线上页面访问本地接口
- jsp页面通过ajax向后台传参实现收藏功能
- Ajax程序中,自己实现页面前进、后退、与标签功能(asp.net2.0)
- Struts 通过拦截器实现登录后跳转到登录前页面 处理普通Http请求和Ajax请求时拦截配置
- Laravel通过ajax的POST方式传值并实现页面跳转
- 利用ICallbackEventHandler接口实现异步调用
- 利用ICallbackEventHandler接口实现无刷新的方法(2)
- Ajax程序中,自己实现页面前进、后退、与标签功能(asp.net2.0)
- 通过AJAX或多线程发送邮件实现页面不滞留
- ASP.NET无刷新客户端回调(通过实现ICallbackEventHandler接口)
- 利用ICallbackEventHandler接口实现无刷新的方法(3)--示例
- 利用ICallbackEventHandler接口实现异步调用
- 使用ICallbackEventHandler接口更高效实现Ajax
- ASP.NET2.0中用ICallbackEventHandler实现客户端与服务器端异步交互
- 使用ICallbackEventHandler接口实现页面无刷新