Here I will explain how to solve the problem “The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).” when running web application using asp.net.
Description:
I created one web application and added some of script files in header section of page like this
<head id="head2" runat="server"> <title>Lightbox Page</title> <link href="aspdotnetsuresh.css" rel="stylesheet" type="text/css" /> <script type="text/javascript" src="<%= ResolveUrl("~/js/LightBox.js") %>"></script> </head> |
Server Error in 'ASP.Net' Application. The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>). Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. |
To solve this problem we have different methods
<head id="head2" runat="server"> <title>Lightbox Page</title> <link href="aspdotnetsuresh.css" rel="stylesheet" type="text/css" /> <script type="text/javascript" src="<%# ResolveUrl("~/js/LightBox.js") %>"></script> </head> |
protected void Page_Load(object sender, EventArgs e) { Page.Header.DataBind(); } |
|
If you enjoyed this post, please support the blog below. It's FREE! Get the latest Asp.net, C#.net, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email. |
|||
Subscribe by RSS
Subscribe by Email
|
|||
|
|
|
Subscribe by RSS
Subscribe by Email
28 comments :
thanks it works....
Another solution of this is to put your script inside body rather than putting it inside head section.
It worked thanks man.
what a simple but great solutions? thanks man...
It worked thanks
Gr8. Good article
Thanks Its Working, great solution, Please can you explain why <%= is not working in this case?
I am not getting value of property its just remove error.
thanks it works....
nice solutions...........thanks
Your posts are very helpful. Keep us posted with your latest updates.
Really thankx , it worked :))
More than the solution to this problem i want to know exactly why this problem happens!!!!!!!
Thanks... It works
thanks.....
Very simple solution...
Thanks.. It worked!
Thanks A Lot.
It worked for me.
Work for me! Thanks man, you're rock!
Hi Friend,
Thanks It works.
good work
Thank you very much It worked for me. Can you please explain the reason why this error come?
Thanks a lot it works for me......
Thanks and saved a lot of time...
great... was looking for that for 2 days
Great Thanks a lot dear It is working .
thanks lot Mr Suresh
thanks suresh....