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.
Exception Details: System.Web.HttpException: The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).
Very silly mistake......now I have share with you.
var lblAgentName = document.getElementById("<%=lblAgent.ClientID%>");
Therefore we have used ASP.Net Server tags to get the ClientID we need to use <% %> tags but unfortunately you cannot add controls dynamically at head section of a page.
It causes the same error.
2. You can use <%# instead of <%=
This changes the code block from a Response.Write code block to a databinding expression. Since <%# ... % > databinding expressions aren't code blocks, the CLR won't complain. If you use Master page then you'd add the following:
protected void Page_Load(object sender, EventArgs e)