Hi Harshraj,
You can do this by calling a microflow on the button from where the page is being shown. this way you will be able to impliment your logic and then you page will be displayed.
Hope it helps!
You could put a DataView with a Microflow datasource on the page. This would be run as the page is being built and before it is shown.
https://docs.mendix.com/refguide/microflow-source/
Is this what you needed?