Set preference value and display the hideable panel

I have a scenario where,
onclick of a button in portlet-1 has to set a preference value and display the hideable panel in portlet-2 after the beforeRenderResponse() method of the portlet-2 has been executed.

I have tried all combinations like setting the action listener, action handler and refreshing the portlet-2 panel from script of portlet-1, similar approach mentioned in the below* link, but the value is getting updated only after the UI refresh and hence the output is blank for the first click, however from the second click onwards the value updates properly.

Other possible simplest way is, could anyone tell me how to set the portlet preference value from a script block?

*http://communities.softwareag.com/ecosystem/communities/public/Developer/webmethods/tutorials/CAF/Confirmation_Dialog_Tutorial/ConfirmDialog_Step10.html

Could anyone help me to fix this issue, please let me know if you need more information?

Hi,
Is the navigation between portlets?
If yes, as you’re setting the value to a preference in Portlet-1, see that you have the same preference is present in Portlet-2 so that preference value will be passed to second portlet.

Once you’ve the preference value in portlet-2, use expression language and bind it to Visible property.

Please let me know if you need a working sample.