views:

24

answers:

2

I have a scenario where...

1.) Have created a div with a dropdown list and ok, cancel button 2.) On document ready - registering div created on step 1 into a jQuery dialog 3.) on a javascript button click - I am opening this dialog box. 4.) Now, the problem is - the jQuery dialogbox which I have created, needs to be used by other button clicks as well on same page. Now, my div's (which is a dialog at runtime using jQuery) ok button click is already engaged with a javascript function (button1 click) and I can not associate other button's click events with it - thus stuck up here and have no clues or hit to resolve this.

Anyone have faced this issue in asp.net, jquery earlier? Can someone provide a guidance?

A: 

Why you cant associate another event?

buttons will have different id. Is it?

$('#button1').click(function() { alert('Handler for button 1 .click() called.'); });

$('#button2').click(function() { alert('Handler for button 2 .click() called.'); });

Is this not possible in your case.?

zod
A: 

Options:

1) disassociate the click handler when the function opens the div, then later in the function of opening the div associate a click handler to the button.

2) create multiple buttons toggle them all hidden, associate the click handler to each button you want. When the div is opened do a check to see which button to toggle to visible.

3) create no buttons but have a function create the button on the fly. When the div is opened, create the button for that div by calling the function and passing in a code telling it which button to open and what to associate to the click handler (this can be stored in an array and all that is passed in is the key).

Depending on the application, I have used all of these methods. The last one can have a twist that allows it to call an ajax server based application to get the button text and functionality (stored in a database), this saves you from having to load an array with button data, and also allows for easier expansion of the application.

met00