Jquery Validation And Update Panel Together not working
Here by adding this code my problem of getting page posted back in spite of having validation error is solved ([blog]: Jquery Validation And Update Panel Together) but it introduced a new one, now by selecting the master dropdown list my child dropdown is not populating I have checked from code behind the targeted method to populate the child dropdown is not firing at all….
<asp:UpdatePanel ID="updRole" runat="server" UpdateMode="Conditional"> <ContentTemplate>
<script type="text/javascript" >
Sys.WebForms.PageRequestManager.getInstance().add_initializeRequest (ins开发者_StackOverflow社区tance_initializeRequest);
function instance_initializeRequest(sender, args) {
if (!Validator())
{args.set_cancel(true);
}
}
</script>
</ContentTemplate>
</asp:UpdatePanel>
This piece of code I have in master page where the validator() function is fired in .ready() event fired by default but the problem was by adding update panel in any content page is method is firing(Validation error is also showing for 2 sec) but page is getting posted back .
<script type="text/javascript">
// only for demo purposes
$.validator.setDefaults({
invalidHandler: function (form, validator) {
}
});
$().ready(function () {
Validator();
});
function Validator() {
var container = $('div.container');
// validate the form when it is submitted
var validator = $("#form1").validate({
errorContainer: container,
errorLabelContainer: $("ul", container),
wrapper: 'li',
meta: "validate"
});
}
</script>
Script in the head:
<script type="text/javascript">
// only for demo purposes
$().ready(function () {
$.validator.setDefaults({
invalidHandler: function (form, validator) { }
});
var container = $("div.container");
$("#form1").validate({
errorContainer: container,
errorLabelContainer: $("ul", container),
wrapper: 'li',
meta: "validate"
});
});
</script>
Script just below the ScriptManager control:
Sys.WebForms.PageRequestManager.getInstance().add_initializeRequest(instance_initializeRequest);
function instance_initializeRequest(sender, args) {
if (!$("#form1").validate().form()) {
args.set_cancel(true);
}
}
精彩评论