A couple weeks ago I tried using ResolveClientUrl in my masterpage to properly link my javascript and CSS files in my MasterPage. When attempting to run the code:

<script src=’<%= ResolveClientUrl(“~/Assets/Includes/Javascript/jquery-1.4.2.min.js”) %>’ type=”text/javascript”></script>

I received a nasty error:

The Controls collection cannot be modified because the control contains code blocks (i.e. <% … %>).

What?!? Well after some research I found an alternative solution using databinding, here are the steps I used to remedy the problem:

  1. Change your server side tags from <%=to <%#

    Example: <script src=’<%# ResolveClientUrl(“~/Assets/Includes/Javascript/jquery-1.4.2.min.js”) %>’ type=”text/javascript”></script>

  2. On the Master Page code behind in the Page_Load event place the following snippet of code:

    Page.Header.DataBind(); 

This should take care of the problem, if you are still having issues tweet me: @tekguy.