This is a migrated thread and some comments may be shown as answers.

Adding the ClientClose function on the fly

1 Answer 50 Views
Window
This is a migrated thread and some comments may be shown as answers.
Stuart Hemming
Top achievements
Rank 2
Stuart Hemming asked on 30 Nov 2011, 02:14 PM
OK. I know I can do this using the .add_close() method on the client-side event.

However, I need to add the function in such a way as to allow me to access objects from the calling functio9n in the callback function. So, I have something like this...
function ProcessToolTipAction(action, ID)
{
    if (action == "<%= GlobalConstants.CommandName.REQUESTINVITE %>")
    {
        var wnd = $find('<%=winInviteSelf.ClientID %>');
        wnd.add_close(function (sender, e)
        {
            var args = e.get_argument();
            if (IsDialogResultOK(args))
            {
                AjaxRequestObject = GetAjaxRequestObject(action, "<%=this.GetType().ToString()%>");
                AjaxRequestObject.AppointmentId = ID;
                AjaxRequestObject.HideInvite = args.HideInvite;
                AjaxRequestObject.SpecialNotes = args.SpecialNotes;
                AjaxRequestJson(AjaxRequestObject);
            }
        });
        wnd.show();
    }
}
And this seems to work just fine.

Except.

The server-size code, invoked by my AjaxRequestJson() call is executed multiple times if the window is opened multiple times.

Now, if I were doing this in the more traditional way (with the callback function being a standalone function) I'd just call remove_close(functionname) in the callback function itself.

So, to the question: what do I pass to the remove_close() function to prevent multiple copies of the nested function from being called?

--
Stuart

1 Answer, 1 is accepted

Sort by
0
Stuart Hemming
Top achievements
Rank 2
answered on 30 Nov 2011, 02:22 PM
Ha!

Sorted.
function ProcessToolTipAction(action, ID) 
    if (action == "<%= GlobalConstants.CommandName.REQUESTINVITE %>"
    
        var wnd = $find('<%=winInviteSelf.ClientID %>'); 
        var func = function (sender, e) 
        
            wnd.remove_close(func);
            var args = e.get_argument(); 
            if (IsDialogResultOK(args)) 
            
                AjaxRequestObject = GetAjaxRequestObject(action, "<%=this.GetType().ToString()%>"); 
                AjaxRequestObject.AppointmentId = ID; 
                AjaxRequestObject.HideInvite = args.HideInvite; 
                AjaxRequestObject.SpecialNotes = args.SpecialNotes; 
                AjaxRequestJson(AjaxRequestObject); 
            
        }
        wnd.add_close(func); 
        wnd.show(); 
    
}

Neat! Gotta love JavaScript!

--
Stuart
Tags
Window
Asked by
Stuart Hemming
Top achievements
Rank 2
Answers by
Stuart Hemming
Top achievements
Rank 2
Share this question
or