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
Harsha ShriHarsha Shri 

Rerender issue in Visualforce page commandbutton

Hi All,
I am having rerender issue in VF page. 
Problem:
when I am putting reRender and rendred together in a commandbutton, when clicking on commandbutton it is not redirecting to the actual page what I mentioned on pagereference method.

This is my code
Apex class:
public class SaveRecords{
 public PageReference saveToCollege() {
    
        Boolean saved = false;
        saved = Class2.saveCollegeData(WrapperData.result,collegeId);
        if(saved)
        {
            PageReference pg=new PageReference('/'+collegeId );
            return pg;
        }
        
    } 
	}
VF Page code:
<apex:page>
	<apex:form>
	  <apex:pageBlock id="mySelectedPB1">
	  
			some code
	  </apex:pageBlock>
	 <apex:commandButton action="{!linkToProject}" value="Link to Project" rerender="mySelectedPB1" rendered="{!if(WrapperData.result != null,true,false)}"/>
	</apex:form>
	</apex:page>

Please suggest me where it is going wrong

Thanks in Advance​
 
Shubham saini 14Shubham saini 14
Hello harsha shri,

you are missing function 'linkToProject' and wrapper class(WrapperData.result) in apex controller and have to mention controller in your vfp like this 
<apex:page Controller="SaveRecords">

Regards
Shubham
 
Harsha ShriHarsha Shri

Hi Shubham

I shared sample code from my VF page. I am using controller class in page tag. My problem is when I click on commandbutton it is saving records but not navigating to what I mentioned in pagereference ethod

Shubham saini 14Shubham saini 14
Hi Shri,
 
PageReference pg = new PageReference('/'+collegeId);
      pg.setRedirect(true);
      return pg;


Try this,

Regards 
Shubham

Harsha ShriHarsha Shri

Hi Shubham,

I tried that. It is not working