Skip to Content
avatar image
Former Member

Passing Parameters to Button Press Handler

Hi everyone.

The following code works:

var oDialog = new sap.ui.commons.Dialog();

oButton = new sap.ui.commons.Button();

oButton.setText("Close");

oButton.attachPress(HandleButtonClick);

oDialog.addButton(oButton);

                

// Open Dialog

oDialog.open();

function HandleButtonClick()

{    oDialog.close();        }

But this doesn't. Basically I'm trying to pass reference of oDialog, so that I can close it at a later stage.

var oDialog = new sap.ui.commons.Dialog();

oButton = new sap.ui.commons.Button();

oButton.setText("Close");

oButton.attachPress(HandleButtonClick(oDialog));

oDialog.addButton(oButton);

                

// Open Dialog

oDialog.open();

function HandleButtonClick(oDialog)

{    oDialog.close();        }

Thanks in advance guys.

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • Best Answer
    avatar image
    Former Member
    Oct 15, 2015 at 07:47 AM

    Hi,

    Try using the following code:

    var oDialog = new sap.ui.commons.Dialog();
    oButton = new sap.ui.commons.Button({
         text: "Close",
         press: HandleButtonClick({dialog: oDialog})
    });
    
    oDialog.addButton(oButton);
    
    //Open Dialog
    oDialog.open();
    
    function HandleButtonClick(oEvent){
         var dialog = oEvent.getParameter("dialog");
    
         oDialog.close();
    }
    
    Add comment
    10|10000 characters needed characters exceeded