We are introducing JQuery to an existing ASP.NET application and use the Validate plugin for JQuery to do the client side validation (we do not want to use the asp.net validators).
Everything works nicely with the asp:Button control. The client side validation is triggered before the page is submitted.
However when using the LinkButton and ImageButton controls the page gets submitted without validating the form first.
This is due to the fact that validate works with Buttons that are rendered as Input type="submit" while the ImageButton renders as Input type="image".
Anyone else experienced this?
Thanks a lot for ideas and infos how to resolve.
Thanks a lot, your answers helped to identify the problem. it turns out that there was a bug in the validate plugin for JQuery. We used a patch to avoid the validation of hidden input fields, which uses parents().filter(":hidden"). This doesn't work properly in JQuery 1.3.2. We replaced it with .is(":visible"). Now the asp.net ImageButton works by default!
The LinkButton still did not work. The simple solution is to add a click function that returns false if the form is not valid:
$("#<%= tb.ClientID %>").click(function() {
return $('form').valid();
})
The first suggestion might still work because you can cause the postback to fire using Javascript after the validation occurs.
The javascript is:
__doPostBack('<%= YourImageControl.UniqueID %>','');
The second empty parameter can be used to pass arguments.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With