Modified to save a data when changing page.