When I add the following line of code in my .aspx file
<% Response.Write(Session("copyrightDate"))%>
I get the following error when I try to run it
Is there a fix for this?
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. <% ... %>).
Source Error:
Line 106: Dim panel As Panel = New Panel()
Line 107: panel.Controls.Add(_viewState)
Line 108: Page.Form.Controls.Add(panel)
Line 109: Dim script As String = ("document.getElementById('" _
Line 110: + (_viewState.ClientID + ("').value = GetViewState__AspNetTreeView('" _
Source File: C:\Documents and Settings\Brian Jones\My Documents\Visual Studio 2005\cis281\App_Code\Adapters\TreeViewAdapter.vb Line: 108
Stack Trace:
[HttpException (0x80004005): The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).]
System.Web.UI.ControlCollection.Add(Control child) +233
CSSFriendly.TreeViewAdapter.SaveAdapterViewState() in C:\Documents and Settings\Brian Jones\My Documents\Visual Studio 2005\cis281\IdeaSystems\App_Code\Adapters\TreeViewAdapter.vb:108
System.Web.UI.Control.SaveViewStateRecursive() +67
System.Web.UI.Control.SaveViewStateRecursive() +194
System.Web.UI.Control.SaveViewStateRecursive() +194
System.Web.UI.Control.SaveViewStateRecursive() +194
System.Web.UI.Page.SaveAllState() +595
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +6647
-bdot
"There are only 10 kinds of people in this world. Those who understand binary and those who don't"
When I use <%# Session("copyrightDate") %> on my master page I dont get an error but it does not display anything
When I use <% Response.Write(Session("copyrightDate"))%> on a .aspx page I dont get an error but it does display the date, but I dont want it on a .aspx page that uses the master...I want it to go in the footer of the master page
This is how i delcared the session in the page load event of the master page
'''''' Current date and time.
Dim currDate As Date = Now
''''''Get only the year of the date
Session("copyrightDate") = DatePart(DateInterval.Year, currDate)
-bdot
"There are only 10 kinds of people in this world. Those who understand binary and those who don't"
Don't worry about my problem...I'm just gonna create a label and set the text equal to currDate...but I would like to why can't you use <% %> in your aspx file
-bdot
"There are only 10 kinds of people in this world. Those who understand binary and those who don't"
bdotjones
Member
240 Points
77 Posts
Controls collection Error
Oct 26, 2006 08:26 AM|LINK
When I add the following line of code in my .aspx file
<% Response.Write(Session("copyrightDate"))%>
I get the following error when I try to run it
Is there a fix for this?
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. <% ... %>). Source Error: Line 106: Dim panel As Panel = New Panel() Line 107: panel.Controls.Add(_viewState) Line 108: Page.Form.Controls.Add(panel) Line 109: Dim script As String = ("document.getElementById('" _ Line 110: + (_viewState.ClientID + ("').value = GetViewState__AspNetTreeView('" _ Source File: C:\Documents and Settings\Brian Jones\My Documents\Visual Studio 2005\cis281\App_Code\Adapters\TreeViewAdapter.vb Line: 108 Stack Trace: [HttpException (0x80004005): The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).] System.Web.UI.ControlCollection.Add(Control child) +233 CSSFriendly.TreeViewAdapter.SaveAdapterViewState() in C:\Documents and Settings\Brian Jones\My Documents\Visual Studio 2005\cis281\IdeaSystems\App_Code\Adapters\TreeViewAdapter.vb:108 System.Web.UI.Control.SaveViewStateRecursive() +67 System.Web.UI.Control.SaveViewStateRecursive() +194 System.Web.UI.Control.SaveViewStateRecursive() +194 System.Web.UI.Control.SaveViewStateRecursive() +194 System.Web.UI.Page.SaveAllState() +595 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +6647"There are only 10 kinds of people in this world. Those who understand binary and those who don't"
Russ Helfand
Contributor
3304 Points
744 Posts
Re: Controls collection Error
Oct 26, 2006 06:06 PM|LINK
Instead of using:
<% Response.Write(Session("copyrightDate"))%>
Try using:
<%# Session("copyrightDate") %>
Groovybits.com
bdotjones
Member
240 Points
77 Posts
Re: Controls collection Error
Oct 27, 2006 12:43 AM|LINK
When I use <%# Session("copyrightDate") %> on my master page I dont get an error but it does not display anything
When I use <% Response.Write(Session("copyrightDate"))%> on a .aspx page I dont get an error but it does display the date, but I dont want it on a .aspx page that uses the master...I want it to go in the footer of the master page
This is how i delcared the session in the page load event of the master page
'''''' Current date and time.
Dim currDate As Date = Now
''''''Get only the year of the date
Session("copyrightDate") = DatePart(DateInterval.Year, currDate)
"There are only 10 kinds of people in this world. Those who understand binary and those who don't"
bdotjones
Member
240 Points
77 Posts
Re: Controls collection Error
Oct 27, 2006 12:51 AM|LINK
"There are only 10 kinds of people in this world. Those who understand binary and those who don't"
Russ Helfand
Contributor
3304 Points
744 Posts
Re: Controls collection Error
Oct 27, 2006 12:53 AM|LINK
Actually, now that I think about it, I would recommend that you replace your <% whatever %> with something like this instead,
<asp:Label runat="server" id="myLabel" Text="<%# Session("copyrightDate") %>" />
And then in your page's Page_Load method you would be sure to do this:
myLabel.DataBind()
Does that make sense?
Groovybits.com
bdotjones
Member
240 Points
77 Posts
Re: Controls collection Error
Oct 27, 2006 01:05 AM|LINK
"There are only 10 kinds of people in this world. Those who understand binary and those who don't"
Kardo
Member
2 Points
2 Posts
Re: Controls collection Error
May 30, 2010 07:51 AM|LINK
Hello,
I had the same problem.
The cause of this error are code blocks with '=' signs in Markup page [<%= %>]. Try to find them in markup page and move them to code behind;
e.g.:
Markup: <a href='<%= ResolveUrl("~/url.ext")%>'>Link Text</a>
Replace above with:
<a id="link1" runat="server">Link Text</a>
Code Behind:
link1.ResolveUrl("~/url.ext");
Attention: Your markup tag should contain both ID="anyID" and RUNAT="SERVER" to be accessible in code behind.
May Allah bless you all,
As for those who believe and do good works, He will pay them their wages in full. Allah does not love the harm doers. [Koran 3.57]
The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).