views:

224

answers:

2

Hi...

I have a masterpage setup, with a pageLoad in the topmost masterpage, which calls pageLoad2 for nested masterpages which calls pageLoad3 for content pages.

In my content page I have a jquery click event and in my nested masterpage I have a web user control.

Whenever I use the user control in the nested masterpage, it rebinds the click event in the content page (undoubtedly because the pageLoad3 is called again), but this makes the click event fire twice on a single click. The problem gets worse the higher up masterpages you go (eg. fires 3 times if user control from topmost masterpage is called).

Can anyone tell me how to make sure it only binds the jquery events once?

A: 

You can use the .One() function, which unbinds the event first.

$("#name").One("click", function(){
  // insert code here
});
Fabian
This doesn't work - as this makes the event only fire once, and then never again. I still need to be able to click as many times as I want to fire the event, just not twice or more on the same click.
Dynde
<OT/> and btw - I LOVE the LOTR connotation of "You can use the .One() function" haha ;)
Dynde
A: 

You could use the .live()-handler so you don't have to bind the controls again and again.

Tim
Funnily enough this actually seems to exacerbate the problem. When directly exchanging the live-hander for the regular click handler - it fires twice even without having used a user control. And it doesn't help placing it in the top masterpage
Dynde
Doh - monday morning I guess, this was my embarrassing screwup - live-handlers of course works perfectly - thank you very much Tim!
Dynde