I have common functions and I collapse it on CommonFunctions.js
in Scripts folder.
I include it on my master page and use it on my pages. When I do any post back on a page, my function doesn't work.
My CommonFunctions.js
:
$(function () {
gf();
if (Sys.WebForms.PageRequestManager.getInstance().get_isInAsyncPostBack()) {
gf();
}
function gf(){
$('.AddNewGeneralPanel').click(function () {
if ($(this).find('.AddNewGeneralPanelStyle').text() == "") {
$(this).find('.AddNewGeneralPanelStyle').text("( Gizle )");
lastOpenId = $(this).attr("kodid");
}
else
$(this).find('.AddNewGeneralPanelStyle').text("");
$(this).next('.AddNewGeneralAccordionDiv').slideToggle('slow', function () {
});
});
}
});
Faced same problem. Change
to
this will force it to run even on partial postbacck
Assuming you are using an UpdatePanel to do the postback and the JS code is attatched to HTML elements within the update panel you need to attach them again when the update panel is loaded. You can hook up your code on the endRequest event:
http://msdn.microsoft.com/en-us/library/bb383810.aspx
Keep in mind that if you are using more than one update panel you should check which update panel is refreshed and attach only the events that are needed otherwise you risk events firing more than once.
It is because of
updatepannel
used. Following code is working fine. Just put yourjquery
code inside thepageLoad
event like belowSince you're using an
UpdatePanel
, the part of the DOM that you've attached your event handler to is getting dropped and recreated after the postback. This has the effect of removing any event handlers that were attached by jQuery when the page first loaded.When you postback only part of the page, the jQuery
$(function() {});
doesn't fire again, so your handlers never get reattached.Here's a related question that shows how to resubscribe your events when the
UpdatePanel
refreshes.It is because of updatepanel partial postbacks. here is what you need to do.
I had the same issue and it worked for me. I hope it helps you too.
i have the same problem, i have solved with this code: