Tuesday, 22 September 2015
How to fix error: The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).
Watch this example on YouTube:
Move javascript code from <Head> to <Body>
Before
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="JSTest.aspx.cs" Inherits="WebApplication1.JSTest" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script type="text/javascript">
function doSomething() {
var test = document.getElementById('<%= TextBox1.ClientID %>')
}
</script>
</head>
<body>
<script type="text/javascript">
function doSomething() {
var test = document.getElementById('<%= TextBox1.ClientID %>')
}
</script>
<form id="form1" runat="server">
<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
</asp:ToolkitScriptManager>
<asp:CalendarExtender ID="CalendarExtender1" runat="server" TargetControlID="TextBox1"></asp:CalendarExtender>
<div>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</div>
</form>
</body>
</html>
After
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="JSTest.aspx.cs" Inherits="WebApplication1.JSTest" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<script type="text/javascript">
function doSomething() {
var test = document.getElementById('<%= TextBox1.ClientID %>')
}
</script>
<script type="text/javascript">
function doSomething() {
var test = document.getElementById('<%= TextBox1.ClientID %>')
}
</script>
<form id="form1" runat="server">
<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
</asp:ToolkitScriptManager>
<asp:CalendarExtender ID="CalendarExtender1" runat="server" TargetControlID="TextBox1"></asp:CalendarExtender>
<div>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</div>
</form>
</body>
</html>
to Before
Subscribe to:
Posts (Atom)