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
Preethi SPreethi S 

how to hide all labels and fields after clicking save button in visualforce page

i dont know where should i give rendered attribute to hide fields.. could u help for this?
VF page:
<apex:page controller="SuccessController1" showheader="false">
<apex:form id="file1">
<apex:pageMessages id="msg"/>
<apex:pageBlock title="CandidateInformation" mode="edit">
<apex:pageBlockSection title="Information" columns="2">
<apex:inputField value="{!cand.FirstName__c}"/>

<apex:inputField value="{!cand.LastName__c}" />


<apex:inputField value="{!cand.SSN__c}" />


<apex:inputField value="{!cand.city__c}" />


<apex:inputField value="{!cand.Phone__c}"  />
<apex:inputField value="{!cand.Email__c}"  />


<apex:commandButton action="{!save}" value="save"/>
<apex:outputPanel id="file1" rendered="{!hidefn}">
</apex:outputPanel>
</apex:pageBlockSection>
</apex:pageBlock>

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

controller:

public with sharing class SuccessController1 {
public boolean hidefn { get; set; }
    public SuccessController1() {

hidefn=false;
    }
Candidate__c cand = new Candidate__c();
Public Candidate__c getCand()
  {
 
   return Cand;
   }
  public SuccessController1(ApexPages.StandardController controller)
    {

      }
      public PageReference save()
      {
      insert cand;
      PageReference p = apexPages.currentPage();
      ApexPages.Message msg=new ApexPages.Message(ApexPages.Severity.CONFIRM,'Record Created Successfully.Thank you!');
      ApexPages.addMessage(msg);
      return p;
      }
    }

But I don't know where we have to use that "rendered "attribute in vf page...after  clicking save button i want to show  success message with blank page...
If i use that rendered attribute in input field.....that field will be hided before giving input...Anyone can help for this..
Best Answer chosen by Preethi S
Pavan Kumar KajaPavan Kumar Kaja
Hi preeti,

Change ur page , controller like below. 

<apex:page controller="SuccessController1" showheader="false">
<apex:pageMessages id="msg"/>
<apex:form id="file1" rendered="{!hidefn}">
<apex:pageBlock title="CandidateInformation" mode="edit">
<apex:pageBlockSection title="Information" columns="2">
<apex:inputField value="{!cand.FirstName__c}"/>

<apex:inputField value="{!cand.LastName__c}" />


<apex:inputField value="{!cand.SSN__c}" />


<apex:inputField value="{!cand.city__c}" />


<apex:inputField value="{!cand.Phone__c}"  />
<apex:inputField value="{!cand.Email__c}"  />


<apex:commandButton action="{!save}" value="save"/>

</apex:pageBlockSection>
</apex:pageBlock>

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

public with sharing class SuccessController1 {
public boolean hidefn { get; set; }
    public SuccessController1() {

hidefn=true;
    }
Candidate__c cand = new Candidate__c();
Public Candidate__c getCand()
  {
 
   return Cand;
   }
  public SuccessController1(ApexPages.StandardController controller)
    {

      }
      public PageReference save()
      {
      insert cand;
      hidefn=false;
      PageReference p = apexPages.currentPage();
      ApexPages.Message msg=new ApexPages.Message(ApexPages.Severity.CONFIRM,'Record Created Successfully.Thank you!');
      ApexPages.addMessage(msg);
      return p;
      }
    }



All Answers

Pavan Kumar KajaPavan Kumar Kaja
Hi preeti,

Change ur page , controller like below. 

<apex:page controller="SuccessController1" showheader="false">
<apex:pageMessages id="msg"/>
<apex:form id="file1" rendered="{!hidefn}">
<apex:pageBlock title="CandidateInformation" mode="edit">
<apex:pageBlockSection title="Information" columns="2">
<apex:inputField value="{!cand.FirstName__c}"/>

<apex:inputField value="{!cand.LastName__c}" />


<apex:inputField value="{!cand.SSN__c}" />


<apex:inputField value="{!cand.city__c}" />


<apex:inputField value="{!cand.Phone__c}"  />
<apex:inputField value="{!cand.Email__c}"  />


<apex:commandButton action="{!save}" value="save"/>

</apex:pageBlockSection>
</apex:pageBlock>

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

public with sharing class SuccessController1 {
public boolean hidefn { get; set; }
    public SuccessController1() {

hidefn=true;
    }
Candidate__c cand = new Candidate__c();
Public Candidate__c getCand()
  {
 
   return Cand;
   }
  public SuccessController1(ApexPages.StandardController controller)
    {

      }
      public PageReference save()
      {
      insert cand;
      hidefn=false;
      PageReference p = apexPages.currentPage();
      ApexPages.Message msg=new ApexPages.Message(ApexPages.Severity.CONFIRM,'Record Created Successfully.Thank you!');
      ApexPages.addMessage(msg);
      return p;
      }
    }



This was selected as the best answer
Virendra ChouhanVirendra Chouhan
Hi Preethi,

you should use "rendered" attribute in "pageBlockSection" or "pageBlock" and create a boolean type of variable which is initialize with "True" in Controller's constructor.
And then in Save method set this variable with false.
so after saving the record all inputFields are hide and only your Success message is shown on page.

i hope this will help you

Regards
Viru
Preethi SPreethi S
Thanks ashi...It is working.....
Preethi SPreethi S
Thanks virendra to clarify my doubts.....