This link explains the whole story:
http://blogs.msdn.com/kaevans/archive/2007/04/26/code-blocks-are-not-allowed-in-this-file-using-server-side-code-with-sharepoint.aspx
The fix is to add this web.config key. In the configuration/SharePoint/PageParserPaths configuration section add something like this:
VirtualPath="/pages/test.aspx" CompilationMode="Always"
AllowServerSideScript="true" />
WARNING: There is a reason why Sharepoint does this so only use it when you need it. It can be dangerous to give designers access to the file and accidentally have them edit your code.