There is a chance sometimes you can get this HttpException: The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>). Just like itself mentioned, if you check your aspx page you must can find some <% ... %> exception inside. There are two ways to fix it.
Option 1: move the code into any runat="server" tag, which means move the code into a server side html tag. The tag could be <head runat="server"></head>, or <form runat="server"></form>.
If you can’t put the code into any server side tag (it is wired if this happen :-) ) then there is Option 2:
Step 1: override the OnInit(), like this:
Then step 2, in your code replace all the <% … %> or <%= … %> to <%# … %>. Done. I will do more research and probably can tell you what actually happened very soon. -- The End
Option 1: move the code into any runat="server" tag, which means move the code into a server side html tag. The tag could be <head runat="server"></head>, or <form runat="server"></form>.
If you can’t put the code into any server side tag (it is wired if this happen :-) ) then there is Option 2:
Step 1: override the OnInit(), like this:
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
Page.DataBind(); // Add this new line.
}
{
base.OnInit(e);
Page.DataBind(); // Add this new line.
}
Then step 2, in your code replace all the <% … %> or <%= … %> to <%# … %>. Done. I will do more research and probably can tell you what actually happened very soon. -- The End
No comments:
Post a Comment