+ Start a Discussion
Balaji B 10Balaji B 10 

how to hide a page block buttons,when working with one,other one is hide?Give me one best Example with more than 3 buttons?

Best Answer chosen by Balaji B 10
JyothsnaJyothsna (Salesforce Developers) 
Hi Balaji,

Please check the below sample code (e.g:Online exam questions)

Visualforce Page:
<apex:page controller="HideShowController">
 <apex:form >
  <apex:pageBlock >
  <apex:pageBlockSection >
  1.question?
  <apex:pageBlockSectionItem >
 <apex:commandButton action="{!answer}" value="YES" rendered="{!answer}"></apex:commandButton>
  <apex:commandButton action="{!skipquest}" value="NEXT" rendered="{!nextquest}"></apex:commandButton>
</apex:pageBlockSectionItem>
      <apex:outputLabel rendered="{!solution}">answer1</apex:outputLabel>
 </apex:pageBlockSection>
 <apex:pageBlockSection >
 <apex:outputLabel rendered="{!quest2}">2.question</apex:outputLabel>
  <apex:pageBlockSectionItem >
 <apex:commandButton action="{!answer1}" value="YES" rendered="{!answer1}" ></apex:commandButton>
  <apex:commandButton action="{!skipquest1}" value="NEXT" rendered="{!nextquest1}" ></apex:commandButton>
</apex:pageBlockSectionItem>

<apex:outputLabel rendered="{!solution2}">answer2</apex:outputLabel>
 </apex:pageBlockSection>
 </apex:pageblock>
 </apex:form>
 </apex:page>

Controller:
public with sharing class HideShowController {


    public boolean solution2 { get; set; }

    public boolean quest2 { get; set; }

    public boolean solution1 { get; set; }

    public boolean solution { get; set; }

    public boolean nextquest1 { get; set; }

    public boolean answer1 { get; set; }

    
   
    public Boolean nextquest { get; set; }
    
     public Boolean answer { get; set; }

   public HideShowController(){
      answer=true;
      nextquest=true;
      solution=false;
      quest2=false;
      solution2=false;
     
     
   }
    public PageReference skipquest() {
       answer=false;
       nextquest1=true;
       quest2=true;
       nextquest=false;
       answer1=true;
       
        return null;
    }


    public PageReference answer() {
       solution=true;
       answer=false;
        return null;
    }

   
    public PageReference skipquest1() {
        return null;
    }


    public PageReference answer1() {
        solution2=true;
       answer1=false;
       
        return null;
    }


 
}


Hope this helps you!
Best Regards,
Jyothsna

All Answers

pconpcon
Can you please expand on what you are trying to do and what have tried.  The information you have provided does not give much to work with and having more specifics would help.  If you have any code that you have and are having problems with, please include it here.

NOTE: When including code please use the "Add a code sample" button (icon <>) to increase readability and make referencing code easier.
DeepthiDeepthi (Salesforce Developers) 
Hi Balaji,

Please check the below sample VF page functionality as you required.
<!------VISUALFORCE PAGE----->
<apex:page controller="ControllerClass">
<apex:form >
        Enter First Value &nbsp;&nbsp;<apex:inputText value="{!a}"/> <br/>
        Enter Second Value &nbsp;&nbsp;<apex:inputText value="{!b}"/><br/>
        <apex:commandButton value="Add" action="{!value1}" rendered="{!v1}"/>
        <apex:commandButton value="Subtract" action="{!value2}" rendered="{!v2}"/>
        <apex:commandButton value="Multiply" action="{!value3}" rendered="{!v3}"/><br/>
        <apex:outputText value="{!res}"/>
</apex:form>
</apex:page>
 
// Controller Class

public class ControllerClass {

    public Integer a { get; set; }
    public Integer b { get; set; }
    public Integer res { get; set; }
    public Boolean v1 { get; set; }
    public Boolean v2 { get; set; }
    public Boolean v3 { get; set; }
    
   public ControllerClass (){
        v1=true;
        v2=true;
        v3=true;
    }   
    public PageReference value1() {
        v1=false;
        v2=true;
        v3=true;
        res=a+b;
        return null;
    }
  public PageReference value2() {
        v2=false;
        v1=true;
        v3=true;
        res=a-b;
        return null;
    }
    public PageReference value3() {
        v3=false;
        v1=true;
        v2=true;
        res=a*b;
        return null;
    }    
}

Hope this helps you!
Best Regards,
Deepthi
JyothsnaJyothsna (Salesforce Developers) 
Hi Balaji,

Please check the below sample code (e.g:Online exam questions)

Visualforce Page:
<apex:page controller="HideShowController">
 <apex:form >
  <apex:pageBlock >
  <apex:pageBlockSection >
  1.question?
  <apex:pageBlockSectionItem >
 <apex:commandButton action="{!answer}" value="YES" rendered="{!answer}"></apex:commandButton>
  <apex:commandButton action="{!skipquest}" value="NEXT" rendered="{!nextquest}"></apex:commandButton>
</apex:pageBlockSectionItem>
      <apex:outputLabel rendered="{!solution}">answer1</apex:outputLabel>
 </apex:pageBlockSection>
 <apex:pageBlockSection >
 <apex:outputLabel rendered="{!quest2}">2.question</apex:outputLabel>
  <apex:pageBlockSectionItem >
 <apex:commandButton action="{!answer1}" value="YES" rendered="{!answer1}" ></apex:commandButton>
  <apex:commandButton action="{!skipquest1}" value="NEXT" rendered="{!nextquest1}" ></apex:commandButton>
</apex:pageBlockSectionItem>

<apex:outputLabel rendered="{!solution2}">answer2</apex:outputLabel>
 </apex:pageBlockSection>
 </apex:pageblock>
 </apex:form>
 </apex:page>

Controller:
public with sharing class HideShowController {


    public boolean solution2 { get; set; }

    public boolean quest2 { get; set; }

    public boolean solution1 { get; set; }

    public boolean solution { get; set; }

    public boolean nextquest1 { get; set; }

    public boolean answer1 { get; set; }

    
   
    public Boolean nextquest { get; set; }
    
     public Boolean answer { get; set; }

   public HideShowController(){
      answer=true;
      nextquest=true;
      solution=false;
      quest2=false;
      solution2=false;
     
     
   }
    public PageReference skipquest() {
       answer=false;
       nextquest1=true;
       quest2=true;
       nextquest=false;
       answer1=true;
       
        return null;
    }


    public PageReference answer() {
       solution=true;
       answer=false;
        return null;
    }

   
    public PageReference skipquest1() {
        return null;
    }


    public PageReference answer1() {
        solution2=true;
       answer1=false;
       
        return null;
    }


 
}


Hope this helps you!
Best Regards,
Jyothsna
This was selected as the best answer