此處提供的代碼用來實現當頁面中的某個Button被點擊後disable掉該頁面中所有的Button從而防止提交延時導致的多次提交基於之前的onceclickbutton腳本
//ASPNET中防止頁面多次提交的代碼:javascript
< script language=javascript>
< !
function disableOtherSubmit()
{ var obj = eventsrcElement;
var objs = documentgetElementsByTagName(INPUT);
for(var i=; i< objslength; i++)
{
if(objs[i]typetoLowerCase() == submit)
{
objs[i]disabled = true;
}
} }
//>
< /script>
//ASPNET中防止頁面多次提交的代碼:
public class PreventMultiClick : SystemWebUIPage
{
protected SystemWebUIWebControlsButton Button;
protected SystemWebUIWebControlsButton Button;
protected SystemWebUIWebControlsLinkButton LinkButton;
protected SystemWebUIWebControlsButton Button;
private void Page_Load(object sender SystemEventArgs e)
{
thisGetPostBackEventReference(thisButton); //保證 __doPostBack(eventTarget eventArgument) 正確注冊
if(!IsPostBack)
{
SystemTextStringBuilder sb = new SystemTextStringBuilder();
sbAppend(if (typeof(Page_ClientValidate) == function) { if (Page_ClientValidate() == false) { return false; }}); //保證驗證函數的執行
sbAppend(if(nfirm(are you sure?)==false) return false;); //自定義客戶端腳本
sbAppend(disableOtherSubmit();); // disable所有submit按鈕
sbAppend(thisGetPostBackEventReference(thisButton)); //用__doPostBack來提交保證按鈕的服務器端click事件執行
sbAppend(;);
ButtonAttributesAdd(onclicksbToString());
}
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASPNET Web Form Designer
//
InitializeComponent();
baseOnInit(e);
}
/// < summary>
/// Required method for Designer support do not modify
/// the contents of this method with the code editor
/// < /summary>
private void InitializeComponent()
{
thisButtonClick += new SystemEventHandler(thisButton_Click);
thisLoad += new SystemEventHandler(thisPage_Load);
}
#endregion
private void Button_Click(object sender SystemEventArgs e)
{
SystemThreadingThreadSleep();
ResponseWrite(Hello world!);
}
}
此處只是disable掉所有的submit button 我覺得其它的可提交控件也是可以通過類似的方法來disable的
以上就是ASPNET中防止頁面多次提交的代碼實現
From:http://tw.wingwit.com/Article/program/net/201311/13332.html