Submit once asp.net buttons with validation group support
Posted by: Marker | Technical | 05.11.2009
Got buttons you don’t want the user to click twice, want to disable them site-wide and have support for .net validation groups?
Here’s the code, we use a class to do the selection and the rel attribute to help define the validation group so we can only hide the button if the form has been validated successfully.
<asp:Button ID=”btnProceed” runat=”server” CssClass=”submit-once” rel=”UserProfile” ValidationGroup=”UserProfile” Text=”Proceed” OnClick=”btnProceed_Click” />
And here’s the sprinkling of jquery you will need (stick it in you base master page for example).
$(document).ready(function() {
// ensure that buttons are only clicked once with this class
$(“.submit-once”).click(function() {
if (Page_ClientValidate($(this).attr(“rel”))) {
$(this).after(“Please wait..”).hide();
}
});
});
Leave a Reply