function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Saurabh AgrahariSaurabh Agrahari 

Identifying the button clicked before calling the action method

Hi All,

Is there any way we can tell from the Controller Extension which button in clicked in the Visualforce Page.

For example in the visualforce page Below:
<apex:page standardController="Account" extensions="AccountExt" >
         <apex:commandButton value="X"  action="{!X_AccountExt}"/>
         <apex:commandButton value="Y"  action="{!Y_AccountExt}"/>

Can we check from the controller extension AccountExt ,which button was clicked by the user.


Saurabh Agrahari

siddarth rajsiddarth raj

From the method call you would understand anyway what was the button being cliked..

X_AccountExt() method being called 'X' button clicked and same for 'Y'
Saurabh AgrahariSaurabh Agrahari
Thanks for the Reply Siddarth,

But let me re-phrase the question ,so that you understand better,

Suppose I modify the visualforce page posted above
<apex:page standardController="Account" extensions="AccountExt" >
2	    <apex:form>
3	         <apex:commandButton value="X" action="{!X_AccountExt}" onclick="js_function()"/>
4	         <apex:commandButton value="Y" action="{!Y_AccountExt}" onclick="js_function()"/>
5	     </apex:form>    
6	</apex:page>

Now this js_function invokes a method in the extension say XY();

So now how can I from XY() method call  X_AccountExt()  or Y_AccountExt() action method based on which button the user clicked.


siddarth rajsiddarth raj
Try this
<apex:commandButton value="X" action="{!X_AccountExt}" onclick="js_function(this)"/>

Pass button instance to JS method call and pass to the method in your controller. Hope this would help you.
Saurabh AgrahariSaurabh Agrahari
Thanks Siddarth

This seems to me a good solution .But for some reason I am not able to get the value in the controller.

I am trying to pass a parameter to the Controller Extension through java script using apex:actionfunction and

The visualforce page and controller code is given below:
<apex:page standardController="Account" extensions="Ext" > 
<script> function js_function(this) { sc(this.value); } 
<apex:commandButton value="X" action="{!X_AccountExt}" onclick="js_function(this)"/> <apex:actionfunction name="sc" action="{!display}" > 
<apex:param id="arg" name="action" value=""/> 
Apex Code:
public class Ext
public string act{get;set;} 
public void display()
{ act=Apexpages.currentPage().getParameters().get('action'); 

Not sure what I am missing.
siddarth rajsiddarth raj
If you want to pass parameters through as param...but must have to be rerendered and you must assing a value to one attribute that must be declared public
Like this
<apex:param name="nameVal" value="{!X}" assignTo="{!abc}" id="xyzbtn" /> 

and Incntroller
you must have 
public String abc {get;set} 

in controller user abc values as parameter value as needed
Saurabh AgrahariSaurabh Agrahari
Hi Siddarth,

Apologies for late reply .I have tried this before many times but could not get this working.

Earlier I have tried something like below:

public class ManageInterfaceWizardExt{

prm = ApexPages.currentPage().getParameters().get('nameVal')


***VF Page***

<apex:actionfunction name="sc"  action="{!popUpDisplayDelete}" />
<apex:param name="nameVal" value="{!X}" id="xyzbtn" />

Could you please explain what do you mean by 'must have to be re-rerendered '.May be I am not rendereing properly that 's why getting null value;