Reputation: 14057
As the title suggests, I am having trouble maintaining my code on postback. I have a bunch of jQuery code in the Head section and this works fine until a postback occurs after which it ceases to function!
How can I fix this? Does the head not get read on postback, and is there a way in which I can force this to happen?
JavaScript is:
<script type="text/javascript">
$(document).ready(function()
{
$('.tablesorter tbody tr').tablesorter();
$('.tablesearch tbody tr').quicksearch({
position: 'before',
attached: 'table.tablesearch',
stripeRowClass: ['odd', 'even'],
labelText: 'Search:',
delay: 100
});
});
</script>
Upvotes: 3
Views: 2588
Reputation: 125538
put your code in
function pageLoad(sender, args) {
/* code here */
}
instead of in $(document).ready(function() { ... });
pageLoad()
is a function that will execute after all postbacks, synchronous and asynchronous. See this answer for more details
Upvotes: 2
Instead of using $(document).ready you should put your code in a function called pageLoad(). The pageLoad() function is by convention wired up to be called whenever the page has a postback/asyncpostback.
Upvotes: 0
Reputation: 27451
alert('test');
Upvotes: 1
Reputation: 7712
If you just have that code hard coded into your page's head then a post back won't affect it. I would check the following by debugging (FireBug in FireFox is a good debugger):
EDIT: Are you using UpdatePanels for your post back? In other words is this an asynchronous postback or a normal full page refresh?
EDIT EDIT: AHhhhh... Ok. So if you're using UpdatePanels then the document's ready state is already in the ready so that portion of jquery code won't be fired again. I would extract the jquery delegate out to a separate function that you can also call after the async postback.
Upvotes: 6
Reputation: 416131
I'm guessing that the postback pre-empts the page's onLoad event, which jQuery needs to hook into to use it's .ready().
Upvotes: 1