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
Raj_SFRaj_SF 

Access one VF page data from another VF page

Hi,
I have created one VF page (Name: vfPageOne) and having my controller to populate data for that VF page. I have defined the "contentType="text/javascript"" for the VF page so that I can include this VF page into another VF page.

I have create another VF page (Name: vfPageTwo) and including 'vfPageOne' into this second VF page.

Here is my code snippet of 'vfPageOne' is.
#*******************************************
<apex:page controller="ctrlOne" contentType="text/javascript">

    <script>
    var srchInput = {!srchData};   // {!srchData} is coming from controller in JSON format.
        alert({!srchData});
    </script>
</apex:page>
#*******************************************


Here is my code snippet of 'vfPageTwo' is.
#*******************************************
<apex:page controller="ctrlTwo">
    <apex:includeScript value="apex/PPF_SearchKeywords"/>
    <script>
         alert(srchInput);
    </script>
    <apex:form >
    <apex:inputText value="{!srchKeyword}" id="srchbox1"/>
    </apex:form>
</apex:page>
#*******************************************

I am trying to access js variable 'srchInput' from 'vfPageTwo' which got populated in 'vfPageOne'. In 'vfPageTwo', i could see the values. But in VF page two, alert() is saying undefined for 'srchInput'. I could have done away with one vf page and controller, but I want to reduce the viewstate size of second VF page.

Let me know how I can achieve this.

richardc020richardc020
I don't know of a way, being only able to include other apex pages as css or js
<apex:stylesheet value="{!$Page.OrderCSS}" />
<apex:includeScript value="{!$Page.OrderJS}" loadOnReady="true"/>