Charity given during one's lifetime is better
Question

Is it better for a person to give charity when he is alive, or can he write in his will that it is to be given after he dies?
Praise be to Allah.The virtue of giving in charity whilst one is in good health: 
It was narrated from Abu Hurayrah (may Allah be pleased with him) that a man came to the Prophet (peace and blessings of Allah be upon him) and said: “O Messenger of Allah, which charity brings a greater reward?” He said, “If you give in charity when you are healthy and miserly, fearing poverty and hoping for richness. Do not delay until you are at the point of death and you say, ‘Give this to So and so, give this to So and so,’ …” (al-Bukhaari, 1330; Muslim, 1713). 
Al-Nawawi (may Allah have mercy on him) said: “Al-Khattaabi said: what this hadeeth means is that miserliness is more likely when one is in good health, so if a person is miserly but he still gives in charity, his intention is more sincere and his reward will be greater, unlike the one who is facing death and no longer has any hope of living. Then he starts to realize that someone else will take his wealth, so his charity in this case is lacking, when compared with charity given when one is in good health. Stinginess is based on the hope of remaining alive and fear of poverty… so a person does not have as much reward for his will, compared to the reward for charity given by one who is healthy and miserly.” 
Al-Haafiz ibn Hajar (may Allah have mercy on him) said: “The hadeeth indicates that paying off debts and giving in charity during one's lifetime when one is in good health is better than doing so after death or when one is sick. The Prophet (peace and blessings of Allah be upon him) referred to that when he said: ‘When you are in good health and being cautious, hoping to be rich…’ because when a person is in good health it is usually harder for him to give money, because the Shaytaan makes him fear for it and makes attractive to him the idea that he may live a long life and need that money, as Allah says (interpretation of the meaning): 
‘Shaytaan (Satan) threatens you with poverty’[al-Baqarah 2:268]
The Shaytaan may also make attractive the idea of being unfair in one's will or revoking it altogether. 
Some of the Salaf said of some wealthy people: “They disobey Allah with regard to their wealth twice, by being stingy with it when it is in their hands – i.e., during their lifetime, and by being extravagant with it when it is no longer in their hands – i.e., after death.” Al-Tirmidhi narrated with a hasan isnaad, which was classed as saheeh by Ibn Hibbaan, that Abu’l-Dardaa’ said in a marfoo’ report: “The likeness of the one who frees slaves and gives in charity when he is dying is that of a person who gives his food away after he has eaten his fill.” This is similar to the hadeeth quoted above. 
Abu Dawood narrated a marfoo’ hadeeth from Abu Sa’eed al-Khudri, which was classed as saheeh by Ibn Hibbaan, which says: “If a man were to give one dirham in charity when he is alive and in good health, that is better for him than giving one hundred when he is dying.”.