Can't change control settings on non-active page

Hello,
I would appreciate advice on the problem below.
While on one page I need to pass values to text boxes on another page and then show that page. The second page and text boxes have global scope. All of them are declared. But when executing all calls fail. This should be a simple code and I have no idea what is happening.
Thanks,
Michael

DECLARATIONS
NexPage WIFIPage(14, 0, “WIFIPage”);
NexText txtSSID(14,4,“txtSSID”);
NexText txtPwd(14,7,“txtPwd”);

// this is list of controls that we listen for events
NexTouch *nex_listen_list[] =
{
&cmdUpdateWF,
&cmdGo,
&cmdUpdateSet,
&cmdSetup,
NULL
};

CALLS IN SETUP
nexInit();
cmdGo.attachPop(cmdGoPopCallback);
delay(1000);

CALLS IN LOOP
nexLoop(nex_listen_list);
delay(1000);

CALLBACK FUNCTION
// this button click loads WIFI settings page
void cmdGoPopCallback(void *ptr)
{

char buffer[100] = {0};

char buffer2[100] = {0};

bool retval;

Serial.println(“cmdGoPopCallback executed”);

if (WIFICredentialsStored){

SSID.toCharArray(buffer,sizeof(buffer),0);

retval=txtSSID.setText(buffer);

if(!retval){

  Serial.println("txtSSID.setText(buffer) failed");

}

Serial.println(buffer);

Password.toCharArray(buffer2,sizeof(buffer2),0);

retval=txtPwd.setText(buffer2);

if(!retval){

  Serial.println("txtPwd.setText(buffer2) failed");

}

Serial.println(buffer2);

}

retval=WIFIPage.show();

if(!retval){

  Serial.println("WIFIPage.show() failed");

}

}

OUTPUT:
cmdGoPopCallback executed
recvRetCommandFinished err
txtSSID.setText(buffer) failed
Fios-2RUKB
recvRetCommandFinished err
txtPwd.setText(buffer2) failed
jaw3750ads6142snow
recvRetCommandFinished err
WIFIPage.show() failed

You can access components on unloaded pages when their variable scope is not set to “local” which is the default value but to “global”.
When using the editor >=1.60, you could also declare a few global variables in the program.s file, update these externally from your code and add some lines to the page postinitialize event code to update your components from the global variables.

Thank you Fjodor.
As I mentioned, they are already global. I have no problem writing to variables from code and then using values to populate controls on page preinitialize event inside Nextion as you suggested. For some strange reason it works with variables, but doesn’t work with controls.
Also, page show() didn’t work.
Michael

If everything fails as you describe, I’d check if the WIFIPage has really the page ID 14 in your HMI project as declared in your code. Since neither showing the page nor addressing component attributes on it, a wrong page ID is most probably the common root.

To make things easier to maintain, I’d do the declarations as follows:
DECLARATIONS
uint8_t wpidx =14; // <=== Put the correct page id here!
NexPage WIFIPage(wpidx, 0, “WIFIPage”);
NexText txtSSID(wpidx,4,“txtSSID”);
NexText txtPwd(wpidx,7,“txtPwd”);

2 Likes