同事写的,收录一下,方法如下:
/// <summary>
/// 防止重复提交
/// </summary>
/// <param name="imaButtons">按键集合</param>
/// <param name="clientID">页面有JS验证的组件</param>
public void RepeatSubmitCheckForRC( List<ImageButton> imaButtons)
{
foreach (ImageButton button in imaButtons)
{
StringBuilder sb = new StringBuilder();
sb.Append("if (typeof(Page_ClientValidate) == 'function') { if (Page_ClientValidate() == false) { return false; }};");
if (button.ID != "saveButton")
{
sb.Append("if(!contentRequiredValidator()){return false};");//富文本编辑为空验证
}
sb.Append("this.disabled = true;");
sb.Append(this.Page.ClientScript.GetPostBackEventReference(button, ""));
sb.Append(";");
button.Attributes.Add("onclick", sb.ToString());
}
}
调用方法的时候
List<ImageButton> imaButtons = new List<ImageButton>();
imaButtons.Add(sumbitButton);
imaButtons.Add(saveButton);
RepeatSubmitCheckForRC(imaButtons);