I received a nasty error:
The Controls collection cannot be modified because the control contains code blocks (i.e. <% … %>).
What?!? Well after some research I found an alternative solution using databinding, here are the steps I used to remedy the problem:
- Change your server side tags from <%=to <%#
- On the Master Page code behind in the Page_Load event place the following snippet of code:
This should take care of the problem, if you are still having issues tweet me: @tekguy.
Today I found an add-in for Visual Studio 2010 that allows you to easily switch the default debug web browser. Click here to download the add-in. Upon install also make sure to follow the instructions:
- Restart Visual Studio 2010
- Goto View -> Toolbars -> Default Browser Switcher
You should now see a new toolbar with 5 browser icons.
ASP.NET has a numerous server side tag syntax, here is my attempt to explain them all:
This is your basic tag for including server side code on a webform or view (MVC).
string testVar = “Hello”;
if (testVar == “Hello”)
This is the equivalent of Response.write, this tag has been around since the classic asp days.
<%= Request.QueryString(“Variable”) %>
Used for outputting databound data via Eval and other databinding methods.
<asp:DataList ID=”dlPhotos” runat=”server”>
<%# Eval(“Filename”) %>
Server side commenting, comparable to <!— —> in HTML.
<%— <asp:Literal ID=”lcName” runat=”server” /> —%>
Used for directive statements, usually found atop your page.
<%@ Import Namespace=”My.Namespace” %>
Very similar to <%= but performs an HTML encode on the data.
<%: Html.Image(“~/images/test.png”) %>