我已经用一些脚本完成了这个。这是代码:
在您的实用程序文件中使用它并在需要时调用
C#
public static void SubmitDisable(System.Web.UI.Page source, ref System.Web.UI.WebControls.Button button)
{
string script = null;
script += "if (typeof(Page_ClientValidate) == 'function')";
script += "{";
//script += " /if client-side does not validate, stop (this supports validation groups)";
//script += " //however before validating attempt, must save and, then restore the page validation / submission state, otherwise";
//script += " //when the validation fails, it prevents the FIRST autopostback from this/other controls";
script += " var oldPage_IsValid = Page_IsValid;";
script += " var oldPage_BlockSubmit = Page_BlockSubmit;";
script += " if (Page_ClientValidate('" + button.ValidationGroup + "') == false)";
script += " {";
script += " Page_IsValid = oldPage_IsValid;";
script += " Page_BlockSubmit = oldPage_BlockSubmit;";
script += " return false;";
script += " }";
script += "}";
//script += "//change button text and disable it";
script += "this.className = 'ButtonPleaseWait';";
script += "this.value = 'Working ...';";
script += "this.disabled = true;";
//script += "//insert the call to the framework JS code that does the postback of the form in the client";
//script += "//The default code generated by ASP (WebForm_DoPostbackWithOptions) will not ";
//script += "//submit because the button is disabled (this is new in 2.0)";
script += source.ClientScript.GetPostBackEventReference(button, null) + ";";
//script += "//MUST RETURN AFTER THIS, OTHERWISE IF THE BUTTON HAS UseSubmitBehavior=false";
//script += "//THEN ONE CLICK WILL IN FACT CAUSE 2 SUBMITS, DEFEATING THE WHOLE PURPOSE";
script += "return true;";
button.Attributes.Add("onclick", script);
}
在页面加载时,您只需调用Util.SubmitDisable(this,buttonID);
CSS:
.ButtonPleaseWait { background: #F3F3F3 url('../images/pleasewait.gif') no-repeat 2px center; border: thin solid #000; width: 100px; height: 25px; color: #333; font-weight: bold; text-indent: 15px; font-size: 1.13em; }
网
只需UseSubmitBehavior="false"
在您的 asp.net 按钮中使用