推荐:ASP.NET2.0中控件的简单异步回调
虽然已经有了ASP.NET AJAX了,最近学习ASP.NET控件的时候,逐步理解了原始的控件异步回调(代码取自《ASP.NET 2.0 高级编程》): 首先,在Render事件中添加好一个事件
以下为引用的内容: RequestHelper.js //功能 : 在javascript中提供QueryString/Cookie/Anchor的访问. /*使用 : var Request = new RequestHelper(); var s = Request.QueryString["id"]; //取得url中的id参数. var c = Request.Cookies["name"]; //取得id为name的cookie值. var a = Request.Anchor; //取得url中定位的锚点名称. */ //更新 : 2008-05-31 RequestHelper.prototype.GetParams = function() { var result = {}; var loc = document.location.toString(); if(loc.indexOf("?") > -1) { var l = loc.lastIndexOf("#") > -1 ? loc.lastIndexOf("#") : loc.length; var param_str = loc.substring(loc.indexOf("?") 1, l); var params = param_str.split("&"); for(var x = 0; x < params.length; x ) { params[x] = params[x].split("="); result[params[x][0]] = params[x][1]; } } return result; } RequestHelper.prototype.GetCookies = function() { var result = {}; var cookie = document.cookie; if(cookie.length > 0) { var reg = /(^[a-zA-z0-9] ?|; [a-zA-z0-9] ?)=/g; var c = cookie.match(reg); if(c) { var n = 0; for(var x = 0; x < c.length; x ) { n = (x < c.length - 1) ? cookie.indexOf(c[x 1].toString()) : cookie.length; var s = cookie.substring(cookie.indexOf(c[x].toString()),n); s = s.split("="); s[0] = s[0].replace(/^; / , ""); result[s[0]] = s[1]; } } } return result; } RequestHelper.prototype.GetAnchor = function() { var Anchor; var loc = document.location.toString() if(loc.lastIndexOf("#") > -1) { Anchor = loc.substring(loc.lastIndexOf("#") 1); } return Anchor; } function RequestHelper() { this.QueryString = this.GetParams(); this.Cookies = this.GetCookies(); this.Anchor = this.GetAnchor(); } |
分享:asp.net客户端回调功能的实现机制
实现的过程基本上就是:让要实现客户端回调功能的页面或者空间实现System.Web.UI.ICallbackEventHandler的接口,即2个方法:void RaiseCallbackEvent(string eventArgument),这个是当客户端触
新闻热点
疑难解答