JQuery dialog: how to find the pressed button inside the event with the pressed button

Im currently defining the variable no. buttons for a jquery dialog like this

    var buttonNames = buttonNamesString.split("|");
    var buttonsOpts = {};
    for (i = 0; i < buttonNames.length; i++) {
       buttonsOpts[buttonNames[i]] = function() { $(this).dialog("close");__doPostBack(postbackControlID, buttonNames[i]);}
    }

And initialize a dialog like this one. (Pay attention to the line buttons: buttonsOpts. The way I pass a variable number of buttons)

var parentElement = popupControl.parent();            
            popupControl.dialog({ 
                                autoOpen: false, 
                                modal: true,
                                buttons: buttonsOpts,                                
                                hide: "explode",
                                open:function(type, data){
                                    $(this).parent().appendTo(parentElement);  
                                    popupControl.css({visibility: "visible"});                                          
                                }  
                                });

The problem is that the button in the buttonNames [i] dialog box is pressed does not return anything in the row, since I was increased to the maximum value.

function () {$ (this) .dialog ("close"); __ doPostBack (postbackControlID, buttonNames [i]);}

Can we access the object that fires the event from the event code in Javascript like we do, using the sender object in .Net events. That would solve the problem.

How can I overcome this? Thanks in advance.

+3
1

, . , .

for (i = 0; i < buttonNames.length; i++) {
       var index = i;
       buttonsOpts[buttonNames[index]] = function() { $(this).dialog("close");__doPostBack(postbackControlID, buttonNames[index]);}
    }

, , i. buttonNames.length. , buttonNames [buttonNames.length], undefined.

: at buttonOpts[buttonNames[index]] ,

+1

All Articles