All articles| All Pictures| All Softwares| All Video| Go home page| Write articles| Upload pictures

Reading number is top 10 articles
sqlserver2000定时自动备份的实现_mssql学习_编程技术
delphi自绘栅格组件(TDrawGrid)使用方法
PHP实例:FCKeditor 的配置和使用方法_[PHP教程]
打造超酷的PHP数据饼图_[PHP教程]
javascript应用实例:网页折叠菜单_JavaScript技术_编程技术
当ASP.NET撞上JSF之应用程序的国际化_[Asp.Net教程]
Sql,server,2005加强的十大安全举措_[SQL,Server教程]
常用PHP函数功能中文对照表_[PHP教程]
WebService,服务和ajax,使用教程一例_.net资料_编程技术
ASP.NET实现图象处理详解_[Asp.Net教程]
Reading number is top 10 pictures
Terrorist smile the largest human history an explosion2
漂亮脸蛋魔鬼身材2
Forced sex girl living abroad2
Summer is most suitable for young people to travel in China10
Chinese paper-cut grilles art appreciation1
粉红蕾丝的美女
yy365网站上的美女2
Look for from human art net, is good--2
这才叫绝色美女1
Sora aoi possession of boudoir2
Download software ranking
Tram sex maniac 2 (H) rar bag11
美女写真2
SP4 for SQL2000
Unix video tutorial20
金山office2007
WebService在.NET中的实战应用教学视频 → 第1集
jBuilder2006
仙剑奇侠传98版歌曲
Sora aoi's film--cangkong_Blue.Sky
电脑知识及技巧大合集
归海一刀 published in(发表于) 2014/1/30 1:12:36 Edit(编辑)
用HttpHandler给Asp.net,1.1加入OnClientClick_[Asp.Net教程]

用HttpHandler给Asp.net,1.1加入OnClientClick_[Asp.Net教程]

用HttpHandler给Asp.net 1.1加入OnClientClick_[Asp.Net教程]

大家用Asp.net 1.1的时候,对asp:button加入客户端的onclick事件,要在code-behind里利用Button的Attributes集合,加入,例如:
this.Button1.Attributes["onclick"] = "return test();";


说来惭愧,没出Asp.net 2.0的时候,虽然觉得这么做有点麻烦,但也没想着要去改进它,直到asp.net 2.0出现,看到了在2.0里,多了OnClientClick这个属性,简化了上面1.1时的做法。


其实,在1.1下面,可以用HttpHandler来达到简化onclick的功能。在这个Handler里,遍历页面的每个控件,发现它存在OnClientClick的Attribute时,就给控件加一个onclick的Attribute,然后在web.config里配置所有的aspx页面用这个HttpHandler处理,这样就达到了我们简化onclick的目的,使asp.net 1.1也支持OnClientClick。



using System.Collections;
using System.Web;
using System.Web.Compilation;
using System.Web.SessionState;
using System.Web.UI;
namespace ZSoft.Web.Controller
{

class AspNet1ExtendHandler : IHttpHandler, IRequiresSessionState
{
IHttpHandler 成员#region IHttpHandler 成员


public bool IsReusable
{
get { return false; }
}


public void ProcessRequest(HttpContext context)
{
string url = context.Request.Path;
IHttpHandler h = PageParser.GetCompiledPageInstance(url,context.Server.MapPath(url),context);
(h as Page).PreRender += new EventHandler(ctx_PreRender);


context.Handler = h;
// 交由Asp.net默认的Handler处理
h.ProcessRequest(context);
}


#endregion



private void ctx_PreRender(object sender, EventArgs e)
{
Extend(sender as Page);
}


private void Extend(System.Web.UI.Control control)
{
string script = GetAttribute(control,"OnClientClick");
if(script != null)
{
AddAttribute(control,"onclick",script);
}
foreach(Control child in control.Controls)
{
Extend(child);
}
}
private string GetAttribute(Control control,string keyword)
{
if(control is WebControl)
{
return (control as WebControl).Attributes[keyword];
}
if (control is HtmlControl)
{
return (control as HtmlControl).Attributes[keyword];
}
}


private void AddAttribute(Control control, string key, string value)
{
string oldValue = GetAttribute(control, key);


if (oldValue != null)
{
if (oldValue.IndexOf(value) != -1) oldValue = oldValue.Remove(oldValue.IndexOf(value), value.Length);
if (!oldValue.EndsWith(";") && oldValue != "") oldValue += ";";
}
value = oldValue + value;
if (control != null)
{
if (control is WebControl)
{
WebControl webCtrl = control as WebControl;
webCtrl.Attributes.Add(key, value);
}
if (control is HtmlControl)
{
HtmlControl htmlCtrl = control as HtmlControl;
htmlCtrl.Attributes.Add(key, value);
}
}
}


}
}


来源:http://www.cnblogs.com/northdevil







添加到del.icio.us 添加到新浪ViVi 添加到百度搜藏 添加到POCO网摘 添加到天天网摘365Key 添加到和讯网摘 添加到天极网摘 添加到黑米书签 添加到QQ书签 添加到雅虎收藏 添加到奇客发现 diigo it 添加到饭否 添加到飞豆订阅 添加到抓虾收藏 添加到鲜果订阅 digg it 貼到funP 添加到有道阅读 Live Favorites 添加到Newsvine 打印本页 用Email发送本页 在Facebook上分享


Disclaimer Privacy Policy About us Site Map

If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.