People will donate more to charity if they make a pledge before receiving an unexpected cash windfall, a study has shown.