ASP.NET防止重复提交的Javascript脚本
2009-09-22 13:00
330 查看
function _doPostBack(){}; if(typeof("__doPostBack")=="function") { _doPostBack=__doPostBack; __doPostBack=_doPostBackNew; } document.attachEvent("onmousemove",_onmousemove); var _isPosting=false; var _divMask=null; function _onmousemove() { if(_divMask) with(_divMask.runtimeStyle) { left=event.clientX+document.body.scrollLeft-4; top=event.clientY+document.body.scrollTop-4; } } function _makeMask() { var div=document.createElement("DIV"); with(div.runtimeStyle) { position="absolute"; zIndex=999999; fontSize="1px"; left=event.clientX+document.body.scrollLeft-4; top=event.clientY+document.body.scrollTop-4; width="8px"; height="8px"; cursor="wait"; backgroundColor="gray"; filter="alpha(opacity=10)"; } try { document.body.insertAdjacentElement("BeforeEnd",div); div.onblur=new Function("this.focus()"); div.focus(); } catch(x){} if(_divMask)_divMask.removeNode(true); _divMask=div; } function _doPostBackNew(sender,args) { if(_isPosting) return event.returnValue=!(event.cancelBubble=true); status="正在更新页面..."; _doPostBack(sender,args); _isPosting=true; _makeMask(); } function _onformsubmit() { if(_isPosting) return event.returnValue=!(event.cancelBubble=true); _isPosting=true; _makeMask(); } new function _attachForms() { with(new Enumerator(document.forms)) for(;!atEnd();moveNext()) { item().attachEvent("onsubmit",_onformsubmit); var div=document.createElement("div"); div.runtimeStyle.width="0px"; div.runtimeStyle.hight="0px"; div.runtimeStyle.overflow="hidden"; div.runtimeStyle.position="absolute"; item(0).insertAdjacentElement("afterbegin",div); div.innerHTML="<INPUT TYPE=Submit name='webformpatchsubmitelement' onclick='return event.returnValue=false' id='webformpatchsubmitelement' value='webformpatchsubmitelement'/>"; } }
把这个作为 <script src=.....js></script-> 的形式Render到每个页面中就可以了。|
如果有PageBase,则在Init的时候用RegisterClientScriptBlock放上去更好,代码如下:
protected override void OnInit(EventArgs e) { ClientScript.RegisterStartupScript(this.GetType(), "NewDoPostBack", @"<mce:script language='javascript' src="js/NewDoPostBack.js" mce_src="js/NewDoPostBack.js" defer='defer'></mce:script>"); base.OnInit(e); }
相关文章推荐
- ASP.NET的防止重复提交的脚本
- ASP.NET利用JavaScript防止重复提交
- Asp.net MVC中防止HttpPost重复提交
- asp.net清除页面缓存,防止页面回退重复提交数据及防止同一用户同时登录
- Asp.Net防止刷新重复提交数据(小记)
- Asp.Net防止刷新重复提交数据
- asp.net防止页面刷新或后退引起重复提交
- ASP.NET防止 重复提交
- Asp.Net防止刷新重复提交数据小记
- asp.net防止页面重复提交
- Asp.Net防止刷新重复提交数据小记
- ASP.NET中防止刷新页面造成表单重复提交
- 关于asp.net 防止重复提交的2种方法(一)
- Asp.Net防止刷新重复提交数据小记
- asp.net防止刷新时重复提交(可禁用工具条刷新按钮)
- ASP.NET防止重复提交
- asp.net防止刷新时重复提交(可禁用工具条刷新按钮)
- asp.net 防止页面刷新重复提交的小技巧
- 防止Asp.net按钮重复提交。
- asp.net 防止用户通过后退按钮重复提交表单