jQuery click event not working after partial view reload ?
Jquery events can be only attached to static elements, In above scenario shown in image the partial view is reloaded after ajax call in its success/done function, so all the elements in it becomes dynamic.
Following is the mistake done by beginners
$('#idBtnSave').on('click',function(){
//your code
});
Above code will only work for first time, as the partial view is reloaded the above click event will not be applicable.
Hence in order to avoid it, and make your click event working, use following technique
$('#idDivParent').on('click', '#idBtnSave', function(){
//your code
});
In case of attaching events on elements in partial view, always use the parent div id in which partial view is loaded and than attach event on element id. By using such technique click event will be always applicable.
This theory is not only for click event but for all types of jquery event
No comments