Question

I have a asp.net MVC partial view, inside it jQuery is used to popup a datepicker for a textbox. A cancel button using Ajax to reload the partial view when it is clicked. All work well in the first load. But after the cancel button is clicked, all the jQuery functionality disappear, for example the datepicker stop showing up for the textbox. Any idea what could be wrong with it?

Was it helpful?

Solution

If you're doing any updates to the partial view via ajax any events bound using jquery will need to be rebound or bind them using jquery live, or jquery on for 1.7+

$(document).on(events, selector, data, handler);        // jQuery 1.7+

OTHER TIPS

When you reload your partial view any handlers on the elements in the old (now replaced) partial will have been lost. You have to rebind them to get the functionality back.

A script block at the end of your partial that binds the handlers would work. Or the code that handles the AJAX success or complete call back can rebind them if you prefer.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top