Master Page, Header, Code Block Problem

I added a script tag with a script block --src='<%=Page.ResolveUrl(" ") %>-- to the head of a master page and got the following error:

"The Controls collection cannot be modified because the control contains code blocks"

The error didn't get thrown on all pages and I was stumped as to what to do, but on a hunch I moved the script tag from the head to the top of the body and voila, no more error.

A quick google didn't turn up anything useful (though other, non-pertinent stuff on the error is out there) so maybe this will help to someone.