Control.ClientID has wrong value

An ASP.NET Controls has a ClientID property. SharePoint Controls inherit from the ASP.NET Controls. The property will give you the ID, the rendered control will have in the HTML source. There is one thing to remember:

The ClientID is valid only, if the control has been added to the Controls of the Page!

ID **before** adding the control ID **after** adding the control FilterButton **ctl00\_m\_Webpart1_**FilterButton

So if you need the ClientID e.g. to pass it to a JavaScript to be able to find the control, make sure you grab the ClientID after the control has been added to the Page.