In the ASP.NET codes tabs, there would be a space at the top of the code window.
When copying the code and pasting it into your project page, without realizing the space at the top, you would get the 500 Server error when running the code.