I have an asp.net page with UpdatePanel and like to make a scroll event hander persist through Ajax calls. I got it working for input element change event (see last example), but I am struggle with the sroll event for the div element.
$(document).ready(function()
{
/* working event fires but not after ajax call */
$("#ctl00_cirsContent_divReportLeft").on("scroll", function() {
alert("test scroll left");
});
/* this one does not work at all */
$(document).on("scroll", "#ctl00_cirsContent_divReportRight", function () {
alert("Test scroll");
});
/* this one works both before and after ajax call */
$(document).on("change", "#ctl00_cirsContent_CtlCalendar1_txtDate", function () {
alert("Test type");
});
});
What am I missing?
Thanks
Try to use $(window)
instead of $(document)
:
$(window).on("scroll", "#ctl00_cirsContent_divReportRight", function () {
alert("Test scroll");
});
Ended up with this solution using the pageLoad event rather than $(document).ready:
function pageLoad(sender, args)
{
if (args.get_isPartialLoad())
{
registerScrollEvent();
}
}
and this in registerScrollEvent
$("div[id$='divReportLeft']").scroll(function () {
.... some code
});