防止.net按钮重复提交的解决方法
解决方法一:
前台按钮:
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" OnClientClick="this.form.submit();this.disabled=true" UseSubmitBehavior="False" />
后台代码:
protected void Page_Load( object sender, EventArgs e )
{
if (Page.IsPostBack)
{
Button1.Attributes.Add("disabled", "disabled");
}
}
关键是红色部分OnClientClick="this.form.submit();this.disabled=true" UseSubmitBehavior="False" 。
解决方法二:
this.btnSubmit.Attributes["onclick"] = this.GetPostBackEventReference(this.btnSubmit) + ";this.disabled=true;"; //防止重复提交