Document.Ready() is not working after PostBack Document.Ready() is not working after PostBack asp.net asp.net

Document.Ready() is not working after PostBack


This will be a problem with partial postback. The DOM isn't reloaded and so the document ready function won't be hit again. You need to assign a partial postback handler in JavaScript like so...

function doSomething() {   //whatever you want to do on partial postback}Sys.WebForms.PageRequestManager.getInstance().add_endRequest(doSomething);

The above call to add_endRequest should be placed in the JavaScript which is executed when the page first loads.


Instead of $(document).ready you could use function pageLoad(){}.

It's automatically called by the ScriptManager on a page, even on a postback.


I've run into this a while ago, as El Ronnoco said, it has to go with the DOM not being reloaded. However you can simply change$(document).ready(function() {to

Sys.Application.add_load(function() {

This will force it to run on every postback.

You can use function pageLoad() as well, but you can only have one pageLoad function, whereas with Sys.Application.add_load, you can add as many handlers as you wish.