Reputation: 1015
I'm attempting to implement jQuery validation in my .NET page (http://jqueryvalidation.org/), and everything is perfect if I use an asp:button control.
<asp:Button ID="ContinueBtn" runat="server" CssClass="button" Text="Continue"
onclick="ContinueBtn_Click" />
With my javascript code inserted, it validates the form just fine, and if no validation errors occur, then it executes the code behind associated with that button.
However, when I try to use a asp:Linkbutton instead, it posts back and the javascript isn't fired (even when I add OnClientClick="return false;").
Bottom line - how can I make the linkbutton behave like the button control?
The javascript code:
$(document).ready(function () {
$("#form1").validate({
rules:
{
<%= FirstName.UniqueID %> :
{
required: true,
rangelength: [3, 12]
}
},
messages:
{
<%= FirstName.UniqueID %> :
{
required: "Please enter your first name",
rangelength: "Please enter minimum 3 characters and Maximum 12 character"
}
}
});
});
Upvotes: 3
Views: 603
Reputation: 55
Simple is to write a click function which checks for form validity
$("#<%= buttonID %>").click(function() {
return $('form').valid();
})
give it a try i hope it will work :)
Upvotes: 1