Hi Shashidhar,
this.getView() refers to your view associated to the controller.
sap.ui.getCore() refers to the core component which is available throughout the application.
In your case, this.getView().byId("idButton2") works. JS Bin - Collaborative JavaScript Debugging
But, if you want to get through core, then view id suffix needs to be added, something like sap.ui.getCore().byId("__xmlview0--idButton2") . JS Bin - Collaborative JavaScript Debugging
Regards,
Sai Vellanki.