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
Sandy singhSandy singh 

how can we hide & show block of section without using span or div tag in visualForce

Hi All,

 

Can any body tell me how can we hide & show block of section without using span or div tag in visualForce.

 

Thanks in advance.

 

Regards,

Sandy

Best Answer chosen by Admin (Salesforce Developers) 
Chamil MadusankaChamil Madusanka

Here is an example for your requirement.

 

<apex:page controller="TestPage4">
  
  <apex:form >
      <apex:pageBlock id="block">
          <apex:pageBlockSection title="Section 1" rendered="{!showSection1}">
          
          </apex:pageBlockSection>
          <apex:pageBlockSection title="Section 2" rendered="{!showSection2}">
          
          </apex:pageBlockSection>
          <apex:pageBlockSection title="Section 3" rendered="{!showSection3}">
          
          </apex:pageBlockSection>
      </apex:pageBlock>
      
      <apex:commandButton action="{!method1}" value="Button1" reRender="block"/>
      <apex:commandButton action="{!method2}" value="Button2" reRender="block"/>
  </apex:form>
</apex:page>

 

public with sharing class TestPage4 {
    public Boolean showSection1{get;set;}
     public Boolean showSection2{get;set;}
     public Boolean showSection3{get;set;}
     
     public TestPage4 ()
     {
         showSection1= false;
        showSection2= true;
        showSection3 = true;
     }

    public PageReference method2() {
       showSection1= true;
        showSection2= false;
        showSection3 = true;
        return null;
    }


    public PageReference method1() {
        showSection1= false;
        showSection2= true;
        showSection3 = false;
        return null;
    }

}

 If a reply to a post answers your question or resolves your problem, please mark it as the solution to the post so that others may benefit.

All Answers

Sanchivan SivadasanSanchivan Sivadasan

Use the rendered attribute.

 

Did this answer your question, if yes please mark this as the solution. Thanks.

Chamil MadusankaChamil Madusanka

Here is an example for your requirement.

 

<apex:page controller="TestPage4">
  
  <apex:form >
      <apex:pageBlock id="block">
          <apex:pageBlockSection title="Section 1" rendered="{!showSection1}">
          
          </apex:pageBlockSection>
          <apex:pageBlockSection title="Section 2" rendered="{!showSection2}">
          
          </apex:pageBlockSection>
          <apex:pageBlockSection title="Section 3" rendered="{!showSection3}">
          
          </apex:pageBlockSection>
      </apex:pageBlock>
      
      <apex:commandButton action="{!method1}" value="Button1" reRender="block"/>
      <apex:commandButton action="{!method2}" value="Button2" reRender="block"/>
  </apex:form>
</apex:page>

 

public with sharing class TestPage4 {
    public Boolean showSection1{get;set;}
     public Boolean showSection2{get;set;}
     public Boolean showSection3{get;set;}
     
     public TestPage4 ()
     {
         showSection1= false;
        showSection2= true;
        showSection3 = true;
     }

    public PageReference method2() {
       showSection1= true;
        showSection2= false;
        showSection3 = true;
        return null;
    }


    public PageReference method1() {
        showSection1= false;
        showSection2= true;
        showSection3 = false;
        return null;
    }

}

 If a reply to a post answers your question or resolves your problem, please mark it as the solution to the post so that others may benefit.

This was selected as the best answer
Aditya.ax1199Aditya.ax1199

Thanks it's really helpful..

smritismriti
Hi, I tried the same code but it is not working. It is showing following error.

Error: TestPage6 Compile Error: The method String getShowSection2() is referenced by Visualforce Page (render) in salesforce.com. Remove the usage and try again.