Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Passing Parameters to Button Press Handler

Hi everyone. The following works:

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

oDialog.setTitle(sName);

               

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 work when I pass the reference of oDialog

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

oDialog.setTitle(sName);

               

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();        }

Basically, to write generic functions.

Former Member
Former Member replied

You can pass the dialog instance as a next parameter after the event listener. In the event listener, you can access the dialog instance referring to *this*.

oButton.attachPress(HandleButtonClick , oDialog );

function HandleButtonClick(){ 

     this.close();       // this -> oDialog

}

2 View this answer in context

Helpful Answer

by
Not what you were looking for? View more on this topic or Ask a question