Mennan Mennan - 1 year ago 102
Javascript Question

After postback my JavaScript function doesn't work in ASP.NET

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 postback on a page, my function doesn't work. (sorry about my en)

My CommonFunctions.js :

$(function () {


if (Sys.WebForms.PageRequestManager.getInstance().get_isInAsyncPostBack()) {


function gf(){

$('.AddNewGeneralPanel').click(function () {

if ($(this).find('.AddNewGeneralPanelStyle').text() == "") {
$(this).find('.AddNewGeneralPanelStyle').text("( Gizle )");
lastOpenId = $(this).attr("kodid");

$(this).next('.AddNewGeneralAccordionDiv').slideToggle('slow', function () {



Answer Source

Since 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.