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

How to show section on VF page on button click

I have a requirement to show a section only on button click. here is the code I have tried, but no luck. can someone tell me what is the error in the below code


VF code :


<apex:page controller="testRenderCtrl">
    <apex:commandButton value="Submit" action="{!submit}" reRender="panelId"/>
    <apex:outputPanel  rendered = "{!flag}"  id = "panelId">
    <apex:pageblock >
        <apex:pageblockSection title = "Contact Information">
            <apex:inputField value="{!con.firstname}"/>
            <apex:inputField value="{!con.lastname}"/>                                              



Controller code


public class testRenderCtrl {
    public Contact con {get;set;}    
    public boolean flag = false;    
    public boolean getFlag(){
        return flag;
    public void setFlag(boolean flg){
        flag = flg;
    public void submit(){
     flag = true;   







public PageReference submit(){
     flag = true; 
     return null;  

 Change your submit() method to the above, and it should work. action="" parameters require a method that takes no parameters and returns a pagereference. You don't even need the rerender on the commandButton.



Try this using javascript on the button click. Sample code is given below :


      <apex:commandbutton onclick = "showsection()">

      function showsection()


      document.getElementById('{!$Component.pageid:formid:pageblocksectionid}').style.display = 'block';



Hope this helps.