开发者

ASP.NET loses jquery bindings after postback

I have asp.net page where I bind in markup js file. Js file working with set of functions mostly by class name. In these functions I get data from server using WCF and only change contols state and data. Also onto the page I do postback. Everything is fine but my jquery fu开发者_C百科nctions don't work after that. After postback I only add a row to grid which is not involved in jquery logic.

But when I changed my logic from

$(document).ready(function ()

$jq("#ctrlID").change(function () {    }); )

to

$(document).ready(function ()

$jq("#ctrlID").live('change', function () {    }); )

everything works fine.

I'm puzzled. What it is? I don't add controls


$(document).ready() executes when DOM is ready. However, it will not fire on ajax async postbacks, so all of your bindings are lost. Live() essentially keeps your bindings 'active' at all times. Another solution would be to use pageLoad() client side event, which is part of the ASP.NET client framework. This method would fire on normal and partial postbacks and you can bind your events there just like you would normally.

function pageLoad(sender, args)
{
// Your event bindings here
}

You can also use args.get_isPartialLoad() to determine if you're in a postback or an async postback.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜