此处提供的代码用来实现当页面中的某个Button被点击后disable掉该页面中所有的Button从而防止提交延时导致的多次提交基于之前的onceclickbutton脚本
//ASPNET中防止页面多次提交的代码:javascript
<scriptlanguage=javascript>
<!
functiondisableOtherSubmit()
{varobj=eventsrcElement;
varobjs=documentgetElementsByTagName(INPUT);
for(vari=;i<objslength;i++)
{
if(objs[i]typetoLowerCase()==submit)
{
objs[i]disabled=true;
}
}}
//>
</script>
//ASPNET中防止页面多次提交的代码:
publicclassPreventMultiClick:SystemWebUIPage
{
protectedSystemWebUIWebControlsButtonButton;
protectedSystemWebUIWebControlsButtonButton;
protectedSystemWebUIWebControlsLinkButtonLinkButton;
protectedSystemWebUIWebControlsButtonButton;
privatevoidPage_Load(objectsenderSystemEventArgse)
{
thisGetPostBackEventReference(thisButton);//保证__doPostBack(eventTargeteventArgument)正确注册
if(!IsPostBack)
{
SystemTextStringBuildersb=newSystemTextStringBuilder();
sbAppend(if(typeof(Page_ClientValidate)==function){if(Page_ClientValidate()==false){returnfalse;}});//保证验证函数的执行
sbAppend(if(nfirm(areyousure?)==false)returnfalse;);//自定义客户端脚本
sbAppend(disableOtherSubmit(););//disable所有submit按钮
sbAppend(thisGetPostBackEventReference(thisButton));//用__doPostBack来提交保证按钮的服务器端click事件执行
sbAppend(;);
ButtonAttributesAdd(onclicksbToString());
}
}
#regionWebFormDesignergeneratedcode
overrideprotectedvoidOnInit(EventArgse)
{
//
//CODEGEN:ThiscallisrequiredbytheASPNETWebFormDesigner
//
InitializeComponent();
baseOnInit(e);
}
///<summary>
///RequiredmethodforDesignersupportdonotmodify
///thecontentsofthismethodwiththecodeeditor
///</summary>
privatevoidInitializeComponent()
{
thisButtonClick+=newSystemEventHandler(thisButton_Click);
thisLoad+=newSystemEventHandler(thisPage_Load);
}
#endregion
privatevoidButton_Click(objectsenderSystemEventArgse)
{
SystemThreadingThreadSleep();
ResponseWrite(Helloworld!);
}
}
此处只是disable掉所有的submit button 我觉得其它的可提交控件也是可以通过类似的方法来disable的
以上就是ASPNET中防止页面多次提交的代码实现