Tuesday, June 5, 2012

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 
(http://stackoverflow.com/questions/6643250/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(instance_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> 

No comments: