Hi.
I have a page with an Ajax Manager that manages a RadMenu, a RadToolbar, a panel, that contains an UserControl, and a RadGrid, and the content of the UserControl is RadGrid dependant.
The trouble I have is when the page is building to be displayed I have the error message
The Controls collection cannot be modified because the control contains code blocks (i.e. <% … %>)
What happens? In the UserControl I have some javascript code, that refers to concrete RadInput or RadDatePicker controls in this UserControl, and its dependant of some QueryString parameter (the aspx page is always the same). In some forums I've read I have to refer the controls with <%# %> instead of <%= %>, or I have to move the javascript code to head section in the main page, but I'm working with an UserControl (ascx file, with no head section).
A sample aspx code I have is:
and the detailsPanel is where the UserControl will be loaded. A UserControl sample code is:
and in the behind code I search at my database for if some fields needs more controls, like required field validators. When at database I detect this I create the control I will add and finally I have a line like this:
where is the exception I have is throwed.
I have a page with an Ajax Manager that manages a RadMenu, a RadToolbar, a panel, that contains an UserControl, and a RadGrid, and the content of the UserControl is RadGrid dependant.
The trouble I have is when the page is building to be displayed I have the error message
The Controls collection cannot be modified because the control contains code blocks (i.e. <% … %>)
What happens? In the UserControl I have some javascript code, that refers to concrete RadInput or RadDatePicker controls in this UserControl, and its dependant of some QueryString parameter (the aspx page is always the same). In some forums I've read I have to refer the controls with <%# %> instead of <%= %>, or I have to move the javascript code to head section in the main page, but I'm working with an UserControl (ascx file, with no head section).
A sample aspx code I have is:
<head id="header" runat="server"> |
<title>FocusOnRisk - DetailForm β</title> |
<link href="Styles/FocusOnRisk.css" rel="stylesheet" type="text/css" /> |
</head> |
<body> |
<form id="form1" runat="server"> |
<div> |
<script type="text/javascript"> |
function OnResponseEndHandler(sender, arguments) |
{ |
<%= toolBar.ClientID %>.attachEvent("OnClientClick","click_handler"); |
} |
</script> |
<radA:RadAjaxManager ID="ajaxMngr" runat="server" ClientEvents-OnResponseEnd="OnResponseEndHandler"> |
... |
</radA:RadAjaxManager> |
<asp:Panel ID="menuPanel" runat="server"></asp:Panel> |
<div style="text-align: right"> |
<asp:Panel ID="toolBarPanel" runat="server"> |
<radTlb:RadToolbar ID="toolBar" runat="server" UseFadeEffect="True" Skin="mac" ButtonHeight="24px" |
ButtonWidth="24px" AutoPostBack="true" CatalogIconImageUrl="" SkinsPath="~/RadControls/Toolbar/Skins" |
ImagesDir="~/Imagenes/" OnOnClick="toolBar_OnClick" OnPreRender="toolBar_PreRender" |
ValidationGroup="GV1"> |
</radTlb:RadToolbar> |
<script type="text/javascript"> |
<!-- |
<%= toolBar.ClientID %>.attachEvent("OnClientClick","click_handler"); |
function click_handler(sender, e) |
{ |
if (sender.CommandName=='DELETE') { |
return confirm('<%= MissatgeDinamic("Del1") %>'); |
} |
} |
--> |
</script> |
</asp:Panel> |
</div> |
<asp:Panel ID="detailsPanel" runat="server"> |
</asp:Panel> |
<br /> |
<radG:RadGrid ID="listGrid" runat="server" PageSize="6" Skin="Glassy" OnNeedDataSource="listGrid_NeedDataSource" |
OnItemCreated="listGrid_ItemCreated" OnSelectedIndexChanged="listGrid_SelectedIndexChanged" |
AllowPaging="True" AllowAutomaticDeletes="false" AllowAutomaticInserts="false" |
AllowAutomaticUpdates="false"> |
... |
</radG:RadGrid> |
</div> |
</form> |
</body> |
and the detailsPanel is where the UserControl will be loaded. A UserControl sample code is:
<script type="text/javascript"> |
function cambiarFecha() |
{ |
var input1 = <%=fechaini.ClientID %>; |
var input2 = <%=fechafin.ClientID %>; |
var today = input1.GetDate(); |
var thisYear = today.getYear(); |
var thisMonth = today.getMonth(); |
var thisDay = today.getDate(); |
var maxDate; |
if (thisDay <= 15) { |
maxDate = new Date(thisYear, thisMonth, 15); |
} |
else |
{ |
maxDate = new Date(thisYear, thisMonth+1, 0); |
} |
input2.SetDate(maxDate); |
input2.SetMaxDate(maxDate); |
input2.SetMinDate(input1.GetDate()); |
} |
</script> |
<table id="Table1"> |
<tr> |
<td><asp:Label ID="lbl_fechaini" runat="server" /></td> |
<td><radCln:RadDatePicker ID="fechaini" runat="server" Width="150" DateInput-ReadOnly="true" |
DateInput-OnClientDateChanged="cambiarFecha" /> |
</td> |
</tr> |
<tr> |
<td><asp:Label ID="lbl_fechafin" runat="server" /></td> |
<td> |
<radCln:RadDatePicker ID="fechafin" runat="server" Width="150" DateInput-ReadOnly="true" /> |
</td> |
</tr> |
</table> |
and in the behind code I search at my database for if some fields needs more controls, like required field validators. When at database I detect this I create the control I will add and finally I have a line like this:
foreach (Control aux in ctrlAux) |
{ |
Controls.AddAt(ctrlAuxPos[idx], aux); |
idx++; |
} |
where is the exception I have is throwed.