tags:

views:

58

answers:

4

I have an aspx page with 5 user controls. I have $(document).ready() in each of these user controls and then one in the main aspx page.

Is this the right approach or I should consider of side effects?

+1  A: 

It is fine, you just cannot guarantee the order in which they functions will be fired.

Being as that reducing the amount of $(document).ready() calls is subjective to the code itself, whether or not it is the correct approach for you to take is hard to say without seeing the code/design.

Quintin Robinson
A: 

Either combine them or don't, there are no side-effects just a little extra script running. Whichever is easier to manage is ok, if you have more than a few controls I'd really look at combining the output somehow.

Nick Craver
+1  A: 

If the controls are independent of each-other and independent of the page, YES it is OK to run $(document).ready() multiple times.

Marko
A: 

This is totally fine unless you need to run them in a specific order.

Shortcut (works the same way):

$(function() {

});
sunn0
I thank you all. But can accept only one as an answer. But all of the answers are correct. So cheers guys.
Projapati