Blog Detail

JQuery Validation in Asp.Net

30 Mar 11
admin
No Comments
Hai,

Using following steps, you can perform JQuery validation in aspx pages.

Step1: Create a script reference to these files in the head section of your page.

src=”JS/jquery-1.3.2.js” type=”text/javascript”

src=”JS/JQuery.Validate.js” type=”text/javascript”

Step2: Add a textbox and a button inside form tag

Step3: Now add following script inside script tag to enable JQuery Validation

$(document).ready(function() {
$(“#form1”).validate({
rules: {
<%=TextBox1.UniqueID %>: {
minlength: 2,
required: true
}
}, messages: {}
});
});

Step3: Run the application and click on the Submit button. The Validation fires and will display the error message.

If you want to display custom messages, make use of the ‘messages’ parameter to specify a custom error message for a field as shown below:

$(document).ready(function() {
$(“#form1”).validate({
rules: {
<%=TextBox1.UniqueID %>: {
minlength: 2,
required: true
}
}, messages: {
<%=TextBox1.UniqueID %>:{
required: “* Required Field *”,
minlength: “* Please enter atleast 2 characters *”
}}
});
});

Happy Programing…

Leave A Comment