+ Start a Discussion
jeffdonthemicjeffdonthemic 

CommandButton not redirecting onclick

I have a Visualforce page with the following code:

Code:
<apex:commandButton value="Sharing" onclick="window.top.location='{!URLFOR($Action.Opportunity.Share,Opportunity.Id)}'" />

 
When clicked, the button only redirects you to the correct page if "Develoment Mode" is check for your user. If not checked, the page simply refreshes the current page.

I've tried with a number of different browsers and still the same results. Any idea?

Thanks
Jeff Douglas
Informa Plc
TehNrdTehNrd
I'm not sure if this will help but it's worth trying:

Code:
onclick="window.top.location='{!URLFOR($Action.Opportunity.Share,Opportunity.Id)}';" />

 I just added a semi-colon

dchasmandchasman
Jeff,

You'll also want to avoid using apex:commandButton just to generate a simple html button element with an onclick. apex:commandButton is meant to be used primarily to invoke a server side action /or initiate a partial page update. We are aware that we are missing a button analog for apex:outputLink (e.g. something like apex:outputButton) but you can easily create your own custom component that provides this functionality yourself.
jeffdonthemicjeffdonthemic
Doug,

Thanks for the feedback. I had a feeling that generating a server-side event was overkill but the code comes straight from Mike Dennenfeldt's examples from the DEV-501 class. I just posted it as I thought it was interesting that it worked properly when Development Mode was enabled.

I did a work around with my own solutions and things are working great. BTW... you guys are doing a great job with Visualforce & Apex; keep up with the good work. I come from the SAP & Java world and speed to market with Visualforce is incredible.

Jeff Douglas
Informa Plc
http://blog.jeffdouglas.com