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

codeling Posts: 1056 Points: 4440
Posted: Friday, January 18, 2019 8:38:13 AM

When I try to "~" character to the path value assigned to the attribute src in a ASP.NET web page,

<script runat="server" type="text/javascript" src="~/jquery.js"></script>

I get the following error from IIS:

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

 

 

 

codeling Posts: 1056 Points: 4440
Posted: Friday, January 18, 2019 8:43:12 AM

Try <%# instead of <%= in the aspx web page under head section

<script type="text/javascript" 
        src="<%# ResolveUrl("~/jquery.js") %>">
</script>

Then in Code Behind of Master page under Page_Load Event

Page.Header.DataBind();

Now you are good to go with either jQuery and JavaScript as well as CSS just you need to change your path in ResolveUrl which file you want to handle CSS, JavaScript, jQuery.

Users browsing this topic
Guest