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
raju123raju123 

How to Hide/show a pageBlock depending upon the button selection?

 

hi,

Please check bellow code in which 2 pageblock sections are there. initially only 1st block we can see. if we click on yes second bolck will apear.

but

My Problem when we click on yes second needs to appear and first block needs to Hide.
Please Can any one help me out
public class Wizard_3a_Controller
{

Boolean testval = false;
public pagereference showSection1() {
setHideshow(true);
return null; }

public pagereference ShowSection2()
{
setHideshow(false);
return null;
}

public Boolean getHideshow()
{
return this.testval;
}
public void setHideshow(boolean s)
{
this.testval = s;
}
}

and
Code:
<apex:page controller="Wizard_3a_Controller">
<apex:form>
<apex:pageBlock>
<apex:pageBlockSection title='Rate Information'>
Are there proposed non-standard electronic rates—<br/>
<apex:commandButton action="{!showSection1}" value='Yes' styleClass='btn' rerender='details'></apex:commandButton>
<apex:commandButton action="{!showSection2}" value='No' styleClass='btn'></apex:commandButton>
</apex:pageBlockSection>
<apex:outputPanel id='details'>
<apex:pageBlockSection id ='newData' title='Discount Rates' rendered='{!hideshow}'>
Enter Proposal range
</apex:pageBlockSection>

</apex:outputPanel>

</apex:pageBlock>
</apex:form>
</apex:page>

vishal@forcevishal@force

Change your VF code to this:

 

<apex:page controller="Wizard_3a_Controller">
<apex:form >
<apex:pageBlock >
<apex:outputPanel id="details">
<apex:pageBlockSection title="Rate Information" rendered="{!!hideShow}"> 
Are there proposed non-standard electronic rates—<br/>
<apex:commandButton action="{!showSection1}" value="Yes" styleClass="btn" rerender="details"></apex:commandButton>
<apex:commandButton action="{!showSection2}" value="No" styleClass="btn" rerender="details"></apex:commandButton>
</apex:pageBlockSection>

<apex:pageBlockSection id="newData" title="Discount Rates" rendered="{!hideshow}">
Enter Proposal range
</apex:pageBlockSection>

</apex:outputPanel>

</apex:pageBlock>
</apex:form>
</apex:page>

 This will hide the first section when you click "Yes". Hope it helps :)