How do I get the ID of a dynamically created button?

Where do you need the ID of the Button?
Create a custom event there and set an input like buttonid. At the button click instead of string debugging cast to for example controller and handle the logic there or string debug it at first.