When using RegisterClientScript do not use this.GetType() …

Quoted from: http://blogs.ipona.com/james/archive/2006/10/03/6710.aspx

Page.ClientScript.RegisterClientScriptBlock(this.GetType(), “Script”, scriptText);
This is not good. Why not? Well, this.GetType() is a way of getting the runtime type of an object. That’s not necessarily the same type as the one in which this bit of code is being declared.
So what? Does that actually make any difference? Well, yes, if anyone ever writes a control that inherits from your control.
If I create a control called Widget that calls RegisterClientScriptBlock() passing this.GetType(), then whenever I put a few Widget controls on the page, the script block will be registered once, and only once. That’s great.
Then later on, I develop a SpecialisedWidget control that inherits from Widget. I drop it onto the page, and suddenly, RegisterClientScriptBlock is getting called with the same script, but two different types – Widget, and SpecialisedWidget. The script block ends up appearing on the page twice. Cue tricky hard to track JavaScript bugs that take ages to find…
Now, if Widget had originally registered that script block passing typeof (Widget) as the type argument instead of this.GetType(), the whole problem wouldn’t arise, because even when the SpecialisedWidgets are registering script on the page, the script is registered with the type qualifier of Widget. And as a side bonus, the IL will be more efficient, because typeof (Widget) is a kind of type literal, which the compiler can embed right into the code, rather than a runtime dispatched method call to a reflection API.