I have created a new web application project using visual studio 2012 using .net 4.5. I have not changed any defaults or added anything other than what comes out of the box.
I have read all over the web this included unobtrusive validation but can find any reference to it other than in the scripts folder webuivalidation which i am guessing is it, although through nuget there are lots of others. If i go to the register pager and click the button not filling anything in i get the default error messages, so again i am guessing its working. link to details about 4.5 script manager i have read http://blogs.msdn.com/b/webdev/archive/2012/09/21/asp-net-4-5-scriptmanager-improvements-in-webforms.aspx
What i want to do is to change the css from the default to bootstrap as shown in the below links:
MVC Twitter Bootstrap unobtrusive error handling
But using either or any method i get errors as i cant get the jQuery.validator object its undefined. Also if trying if $(this).valid() gives an error of not supported. So please can someone help and explain it to me as it appears the validate bits are not there?. I have tried for hours with no success or real understanding of the problem.
Thanks Jon
***** code bits ***
2 bits of code i have tried from the above links, not written by me (i have tried editing but still couldnt get it to work):
$('form').submit(function () {
if ($(this).IsValid()) {
$(this).find('div.control-group').each(function () {
if ($(this).find('span.field-validation-error').length == 0) {
$(this).removeClass('error');
}
});
}
else {
$(this).find('div.control-group').each(function () {
if ($(this).find('span.field-validation-error').length > 0) {
$(this).addClass('error');
}
});
}
});
$('form').each(function () {
$(this).find('div.control-group').each(function () {
if ($(this).find('span.field-validation-error').length > 0) {
$(this).addClass('error');
}
});
});
Also:
jQuery.Page_Validators.setDefaults({
highlight: function (element, errorClass, validClass) {
if (element.type === 'radio') {
this.findByName(element.name).addClass(errorClass).removeClass(validClass);
} else {
$(element).addClass(errorClass).removeClass(validClass);
$(element).closest('.control-group').removeClass('success').addClass('error');
}
},
unhighlight: function (element, errorClass, validClass) {
if (element.type === 'radio') {
this.findByName(element.name).removeClass(errorClass).addClass(validClass);
} else {
$(element).removeClass(errorClass).addClass(validClass);
$(element).closest('.control-group').removeClass('error').addClass('success');
}
}
});
$(document).ready(function () {
$('span.field-validation-valid, span.field-validation-error').each(function () {
$(this).addClass('help-inline');
})
});