It is narrated from Sayyiduna Abdullah bin Arqam (may Allah be pleased with him) that he said: I heard the Messenger of Allah (peace and blessings be upon him) say: "When one of you wishes to go to the toilet and the prayer has begun, let him first go to the toilet."
Hadith Referenceالمعجم الكبير للطبراني / باب العين / 14053