All perfect praise be to Allaah, The Lord of the Worlds. I testify that there is none worthy of worship except Allaah, and that Muhammad is His slave and Messenger.
It is lawful to seek closeness to Allaah by doing any good deed and asking Allaah for something in this worldly life or the Hereafter. This is among the lawful ways of Tawassul. The evidence for this is the Hadeeth known as the "Hadeeth of the three who were blocked by a large big stone" It is a long Hadeeth reported by Al-Bukhari and Muslim from Ibn 'Umar that the Prophet said: "...and each of the three people (who were trapped) asked Allaah by a good deed he performed for the sake of pleasing Allaah Alaone, so that Allaah would make a way out for them. One of them asked Allaah with the obedience to his parents, the second one asked Allaah with refraining from Zina (fornication or adultery) due to only fearing Allaah, and the third one asked Allaah for his fulfilling his trust and returning the rights to their owners.
Another evidence for this is the Hadeeth reported by At-Tabaraani and Al-Bayhaqi and which was narrated by Ibn Mas'ood that the Prophet said: "Treat your sick people by giving charity.”
A third way is to perform the prayer for a need; for more benefit in this regard, please refer to Fatwa 82384.
However, we remind our dear brother that anyone who does an act just to get something done in this life, then he gets what he intends and he has nothing in the Hereafter. This is mentioned in a Hadeeth reported by Al-Bayhaqi .
Therefore, whoever does a good deed in order to get a benefit of this worldly life, he should intend to get the reward from Allaah in both this life and the Hereafter.
Allaah Knows best.