This is a migrated thread and some comments may be shown as answers.

The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>)

10 Answers 465 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
Jonathan
Top achievements
Rank 1
Jonathan asked on 20 Dec 2011, 10:21 AM
Hi

I am currently upgrading our Telerik controls from Telerik.WebControls to the latest version of the Telerik.Web.UI controls.

I have replaced all of the old references and matched these to the new dll reference in the pages. Updated all methods/properties/declarations that have changed.

However, i am repeatedly getting this error on the page which is setup with an aspx page with many ascx controls registered to that aspx page:

The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).


I have read your forums regarding place all script out of the head tag and inside the body, replace all <%= with <%#, and wrap any script in a <RadCodeBlock> however none of this is working.

I am needing urgent help on this error!

Regards,
Jonathan

10 Answers, 1 is accepted

Sort by
0
Veli
Telerik team
answered on 20 Dec 2011, 10:34 AM
Try the RadScriptBlock instead of RadCodeBlock. If the issue persists, consider opening a regular support ticket where you can send us a small test project we can debug locally. This will help us better identify your scenario and advise you further.

Veli
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
0
Jonathan
Top achievements
Rank 1
answered on 20 Dec 2011, 10:51 AM
I tried the RadCodeBlock and still get the same error.

I came across the below post, and this suggests he started getting the error when adding a telerik control to a control.

http://www.telerik.com/community/forums/aspnet-ajax/ajax/232173-the-controls-collection-cannot-be-modified-because-the-control-contains-code-blocks-i-e-lt-gt.aspx 

Can I ask if this is simply related to script existing in the <head> tag or if it can persist because of a telerik control being registered in one of the controls?

We use a variety of telerik controls in the controls registered to my problem page (RadComboBox, RadToolBar, RadTabStrip, RadGrid, RadAjaxLoadingPanel) 
0
Jonathan
Top achievements
Rank 1
answered on 21 Dec 2011, 12:36 PM
I have managed to get my page rendering now, however I have had to completely remove one of the controls that registers to the page.

My setup is now an aspx page, which has ascx controls registered to that page, one of those controls then registers another ascx control (The problem one I have had to remove for time being).

The problem control that is being registered contains multiple ascx controls registered within it. Whenever I remove these controls the page renders. 

Inside all of these controls I have wrapped this with a RadCodeBlock and/or RadScriptBlock but it is not rendering the page at all.

Can someone look at this scenario for me and provide me with an answer? Is the issue the fact controls are being registered within controls? Surely this shouldn't cause an issue

Its becoming too much of a labouring task now to update to your latest version of controls and integrate these with our application.
0
Veli
Telerik team
answered on 21 Dec 2011, 01:04 PM
Are you using any binding expressions in your markup. Try disabling the expressions and see if it makes any difference. To assist you further, we need to be able to reproduce your issue locally.

Veli
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
0
Jonathan
Top achievements
Rank 1
answered on 22 Dec 2011, 04:04 PM
Hi Veli

Thank you for your response.

I have traced the problem to where we carry out the following on our controls to ajaxify them:

Firstly we call our own IntialiseAjax() Method.


private void InitialiseAjax()
        {
            // clientside js needs these values
            Page.ClientScript.RegisterClientScriptBlock(GetType(), "global_vars"@"
                var CurrentNodePanelMember_ClientID = '" + CurrentNodePanelMember.ClientID + @"_ddl';
                var CurrentNodePanelMemberOrganisation_ClientID = '" + CurrentNodePanelMemberOrganisation.ClientID + @"_ddl';"true);
 
			WorkflowAndNode.InitialiseAjax(_ajaxManager, LoadingPanel);
 
            // have to pass in null for the loading panel otherwise there'll be two
			MilestoneSchedule.InitialiseAjax(_ajaxManager, null);
 
            if (bool.Parse(ConfigurationManager.AppSettings["AjaxifySearchDDls"].ToString()))
            {
				OwnerOrganisation.InitialiseAjax(_ajaxManager);
                //RevisionCreatedByOrganisation.InitialiseAjax(_radAjaxManager);
				CurrentNodePanelMemberOrganisation.InitialiseAjax(_ajaxManager);
				IssuedTo.InitialiseAjax(_ajaxManager);
				AuthorName.InitialiseAjax(_ajaxManager);
				CurrentNodePanelMember.InitialiseAjax(_ajaxManager);
				StateSetByID.InitialiseAjax(_ajaxManager);
 
				MilestoneSchedule.InitialiseAjax(_ajaxManager, null);
				IssuePurpose.InitialiseAjax(_ajaxManager);
            }
        }


From here the controls IntialiseAjax then carry out the following:


public void InitialiseAjax(RadAjaxManager radAjaxManager)
        {
            radAjaxManager.AjaxSettings.AddAjaxSetting(radAjaxManager, this.ddl);
        }
        public void InitialiseAjax(RadAjaxManager radAjaxManager, RadAjaxLoadingPanel RadAjaxLoadingPanel)
        {
            radAjaxManager.AjaxSettings.AddAjaxSetting(radAjaxManager, this.ddl, RadAjaxLoadingPanel);
        }


Bearing in mind we have changed from Rad Classic controls to the latest version of RadAjax, is there a problem in how we are adding these Ajax settings?

Jonathan
0
Veli
Telerik team
answered on 23 Dec 2011, 09:31 AM
The code you have posted does not give us any clues as to what may be causing the exception you have reported. On a side note, the AJAX settings you are adding seem fine. Note, however, that all AJAX settings that RadAjaxManager will be the control that updates all the other controls. If you need some controls to update themselves, you need add additional settings specifying the target control is both the initiator and the updated control in an AJAX request.

Veli
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
0
Jonathan
Top achievements
Rank 1
answered on 04 Jan 2012, 11:39 AM
Veli

I am still experiencing the same problem when I am trying to add an AjaxSetting to the manager.

Here's what I have for the page I am trying to add it to:

RadAjaxManager radAjaxManager = RadAjaxManager.GetCurrent(Page);
				Control btnSearch = FindControl("btnSearch");
				Control updatedPanel = ((SearchResultsList)(Page.FindControl("resLst"))).UpdatedPanel;
				RadAjaxLoadingPanel radAjaxLoadingPanel = ((SearchResultsList)(Page.FindControl("resLst"))).RadAjaxLoadingPanel;
 
				radAjaxManager.AjaxSettings.AddAjaxSetting(btnSearch, updatedPanel, radAjaxLoadingPanel);

This throws the error: 

The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).

When i comment the below line out the error no longer occurs, however the buttons i am trying to Ajaxify no longer updates the control I want it to. Can you post a possible work around for this or a reason why I am unable to use the AjaxSettings.AddAjaxSettings?

Jonathan

0
Jayesh Goyani
Top achievements
Rank 2
answered on 04 Jan 2012, 03:00 PM
Hello,

we are not able to use UpdatePanel and RadAjaxManager st same time/control.

Please provide your code so we can resolve the issue in your code.

Thanks,
Jayesh Goyani
0
Jonathan
Top achievements
Rank 1
answered on 06 Jan 2012, 12:23 PM
I have managed to trace the problem to the following line in my client-side script:

function GetRadGrid()
{
    return window['grid_' + '<%=grd.ClientID%>'];
}

I have since updated this to match the recommended syntax telerik provide:

<telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
<script type="text/javascript">
function GetRadGrid(){
return $find("<%=grd.ClientID %>"); } </script/> </telerik:RadCodeBlock>
We use the $find method in a lot of places to return objects that we need to perform actions on the grid and with the ajax manager.

I find this a complete joke in terms of getting our application to work with the new telerik controls. Your page on migration from RadAjax ASP.NET to RadAjaxManager ASP.NET AJAX suggests this is a painless process and we are finding this to be anything but that.

We need a solution to access these objects client side since following the telerik document causes the error reported

Below is the grid declaration:

<asp:panel id="updatePanel" runat="server">
	<radG:RadGrid	ID="grd" 
					Skin="orange" 
					Style="padding-left0px" 
					runat="server" 
					EnableAJAXLoadingTemplate="false" 
					AllowCustomPaging="true" 
					enableasyncrequests="false" 
					AllowPaging="false" 
					PageSize="10"
					AllowSorting="true" 
					AutoGenerateColumns="false" 
					showheaderswhennorecords="true" 
					AllowMultiRowSelection="true" 
					CssClass="GenericDataGrid" 
					applystylesonclient="false"
					OnNeedDataSource="cRadGrid1_NeedDataSource" 
					OnItemDataBound="cRadGrid1_ItemDataBound" 
					OnDataBinding="cRadGrid1_DataBinding"
					OnDataBound="cRadGrid1_DataBound"
					OnSortCommand="cRadGrid1_SortCommand"
					EnableEmbeddedSkins="false"
					>
		<HeaderStyle			CssClass="genericGridHeader" />
		<AlternatingItemStyle	CssClass="genericAltItem" 
								Wrap="false" />
		<ItemStyle				CssClass="genericItem" 
								Wrap="false" />
		<SelectedItemStyle		CssClass="genericGridSelectedItem" />
		<MasterTableView		TableLayout="Fixed" 
								Width="100%" 
								AllowMultiColumnSorting="False" 
								AllowCustomSorting="true" 
								AllowNaturalSort="false">
			<Columns>
				<radG:GridTemplateColumn	Resizable="false" 
											UniqueName="TemplateColumnTick" 
											Reorderable="false" 
											HeaderImageUrl="~/Icons/Tick.gif">
					<HeaderStyle						Width="30px" />
					<ItemTemplate>
						<div align="center">
							<asp:Image runat="server" Style="visibilityhidden" ID="cImageTick" ImageUrl="~/Icons/Tick.gif" />
						</div>
						<input type="hidden" runat="server" id="hidGUID" name="hidGUID" />
						<input type="hidden" runat="server" id="hidType" name="hidType" />
						<input type="hidden" runat="server" id="hidStates" name="hidStates" />
						<input type="hidden" runat="server" id="hidName" name="hidName" />
						<input type="hidden" runat="server" id="hidContainerType" name="hidContainerType" />
						<input type="hidden" runat="server" id="hidPropURL" name="hidPropURL" />
						<input type="hidden" runat="server" id="hidRevisionID" name="hidRevisionID" />
						<input type="hidden" runat="server" id="hidFileID" name="hidFileID" />
						<input type="hidden" runat="server" id="hidMarkupID" name="hidMarkupID" />
						<input type="hidden" runat="server" id="hidSearchContainerType" name="hidSearchContainerType" />
						<input type="hidden" runat="server" id="hidParentID" name="hidParentID" />
						<input type="hidden" runat="server" id="hidContainerID" name="hidContainerID" />
						<input type="hidden" runat="server" id="hidIsCurrentRevision" name="hidIsCurrentRevision" />
						<input type="hidden" runat="server" id="hidRowIndex" name="hidRowIndex" />
						<input type="hidden" runat="server" id="hidLinkedToID" name="hidLinkedToID" />
					</ItemTemplate>					
				</radG:GridTemplateColumn>
				<radG:GridTemplateColumn	Resizable="false" 
											UniqueName="Selector" 
											Reorderable="false"
											Display="false"
											Visible="false"
											>
					<HeaderStyle						Width="30px" 
														HorizontalAlign="Center" 
														VerticalAlign="Middle" />
					<HeaderTemplate>
						<input id="chkTogglePicks" type="checkbox" style="padding-left4pxmargin-left:-4px;" onclick="TogglePicks(this.checked);" />
					</HeaderTemplate>						
					<ItemTemplate>
						<input type="hidden" runat="server" id="HiddenSelected" name="HiddenSelected" value="false" />
						<asp:Image border="0" runat="server" Style="padding-left4pxmargin-left:-4px;" ID="imgPlus" ImageUrl="~/icons/tree/GreyPlus.gif" Height="20" Width="20" />
					</ItemTemplate>	
					
				</radG:GridTemplateColumn>
				<radG:GridTemplateColumn	Resizable="false" 
											HeaderImageUrl="~/icons/mouse-clickme_SV_16_B.gif" 
											UniqueName="TemplateColumnRightClick" 
											Reorderable="false">
					<HeaderStyle						Width="30px" 
														HorizontalAlign="Center" 
														VerticalAlign="Middle" />
					<ItemTemplate>
						<asp:Image border="0" runat="server" Style="padding-left4px;" ID="Image1" ImageUrl="~/Icons/right-click_SV_16_B.gif" alt="Right click to see the actions you can perform on this item" Height="16" Width="16" />
					</ItemTemplate>					
				</radG:GridTemplateColumn>
				<radG:GridTemplateColumn	Resizable="false" 
											HeaderImageUrl="~/Icons/lock/s/lock2_14x14.gif"
											HeaderText="Indicates if the item is private"
											UniqueName="Private" 
											Visible="false" 
											Reorderable="false">
					<HeaderStyle						Width="30px" 
														HorizontalAlign="Center" 
														VerticalAlign="Middle" />
					<ItemTemplate>
						<asp:Image ID="imgIsPrivate" runat="server" style="padding-left4pxmargin-top3px;" ImageUrl="~/Icons/lock/s/lock2_14x14.gif" ToolTip="This item is private." />
					</ItemTemplate>					
				</radG:GridTemplateColumn>
				<radG:GridTemplateColumn    Resizable="false" 
											UniqueName="TemplateColumnVCard" 
											Visible="false" 
											Reorderable="false">
					<HeaderStyle						Width="35px" 
														HorizontalAlign="Center" 
														VerticalAlign="Middle" />
					<ItemTemplate>
						<div align="center" nowrap>
							<asp:Image ID="VCardImage" runat="server" ImageUrl="~/icons/vcard.gif" style="cursorpointer;" />
						</div>
					</ItemTemplate>		
				</radG:GridTemplateColumn>
				<radG:GridTemplateColumn	Resizable="false" 
											UniqueName="TemplateColumnHasFiles" 
											Visible="false" 
											Reorderable="false">
					<HeaderStyle						Width="30px"
														HorizontalAlign="Center" 
														VerticalAlign="Middle" />
					<ItemTemplate>
						<div align="center" class="itbl" nowrap>
							<div class="itd">
								<asp:Image ID="HasImage" runat="server" ImageUrl="~/icons/transparentimage16x16.gif" />
								<asp:Image ID="HasLocationImage" runat="server" ImageUrl="~/icons/location2.gif" Width="5" Height="7" Style="displayblockpositionrelativetop-7left0;" />
							</div>
							<div id="updateIcon" runat="server" class="itd">
								<asp:Image ID="imgHasAttachments" Visible="false" runat="server" ImageUrl="~/icons/paperclip_SV_16_B.png" />
								<asp:Image ID="imgIsPublic" Visible="false" runat="server" ImageUrl="~/icons/lock/s/lock_open.png" />
								<asp:Image ID="HasMarkup" ImageUrl="~/icons/Markup_SV_16_B.GIF" Height="16" Width="13" runat="server" Visible="False" />
							</div>
						</div>
					</ItemTemplate>					
				</radG:GridTemplateColumn>
				<radG:GridTemplateColumn	Resizable="false" 
											UniqueName="Workflow2" 								
											Reorderable="false" 
											Visible="false" 
											HeaderText="Workflow"
											SortExpression="HeaderActivityStatusName">
					<HeaderStyle						Width="35px" 
														HorizontalAlign="Center" 
														VerticalAlign="Middle" />
					<ItemTemplate>
						<span>
							<div align="center" style="width10px;" nowrap>
								<asp:Panel ID="pnlWorkflow2" runat="server">
								</asp:Panel>
							</div>
						</span>
					</ItemTemplate>					
				</radG:GridTemplateColumn>
				<radG:GridTemplateColumn	Resizable="false" 
											UniqueName="Workflow" 
											SortExpression="ActivityStatusName" 
											Reorderable="false" 
											Visible="false" 
											HeaderText="Revision Workflow">
					<HeaderStyle						Width="35px" 
														HorizontalAlign="Center" 
														VerticalAlign="Middle" />
					<ItemTemplate>
						<span>
							<div align="center" style="width10px;" nowrap>
								<asp:Panel ID="pnlWorkflow" runat="server">
								</asp:Panel>
							</div>
						</span>
					</ItemTemplate>					
				</radG:GridTemplateColumn>				
				<radG:GridTemplateColumn	UniqueName="Thumbnail" 
											Reorderable="true"
											HeaderText="Thumbnail"
											Resizable="true"  
											Display="false"
											Visible="false"
											HeaderStyle-Font-Bold="false"
											HeaderStyle-ForeColor="Black">
					<HeaderStyle Width="125px" />
					<ItemTemplate>
						<div align="center">
							<cc1:DynamicImage id="imgThumb" runat="server" Visible="false" />
						</div>
					</ItemTemplate>					
				</radG:GridTemplateColumn>
				<radG:GridBoundColumn		UniqueName="WorkflowForExport" 
											DataField="ActivityStatusName" 
											HeaderText="Workflow Status" 
											Visible="false">
					<HeaderStyle						Width="35px" 
														HorizontalAlign="Center" 
														VerticalAlign="Middle" />
				</radG:GridBoundColumn>
				<radG:GridBoundColumn		UniqueName="Workflow2ForExport" 
											DataField="HeaderActivityStatusName" 
											HeaderText="Workflow Status" 
											Visible="false">
					<HeaderStyle						Width="35px" 
														HorizontalAlign="Center" 
														VerticalAlign="Middle" />
				</radG:GridBoundColumn>
			</Columns>
		</MasterTableView>
		<ClientSettings			AllowColumnHide="True" 
								AllowDragToGroup="true" 
								AllowColumnsReorder="True" 
								ReorderColumnsOnClient="True"
								ColumnsReorderMethod="Reorder">
			<Selecting						AllowRowSelect="true" 
											EnableDragToSelectRows="false" />
			<Resizing						ClipCellContentOnResize="true" 
											AllowRowResize="false" 
											EnableRealTimeResize="false" 
											AllowColumnResize="true" 
											ResizeGridOnColumnResize="false" />
			<ClientEvents					OnColumnResized="ColumnResized" 
											OnColumnSwapped="ColumnSwapped"
											OnGridCreated="SetContextMenu" 
											OnRowSelected="RowSelected" 
											OnRowDeselected="RowDeselected" 
											OnRowCreated="RowCreated" 
											OnRowContextMenu="RowContextMenu"
                                            OnRowClick="RowClicked" 
											OnColumnContextMenu="RGColumnContext" />
			<Scrolling						AllowScroll="false" 
											UseStaticHeaders="false" />
		</ClientSettings>
	</radG:RadGrid>
	<hex:nav id="NavBar" runat="server"	
		OnNav_ChooseNumberClick="NavBar_Nav_ChooseNumberClick" OnNav_FirstPageClick="NavBar_Nav_FirstPageClick"
		OnNav_LastPageClick="NavBar_Nav_LastPageClick" OnNav_NextPageClick="NavBar_Nav_NextPageClick"
		OnNav_PreviousPageClick="NavBar_Nav_PreviousPageClick" OnNav_ChangePage="NavBar_Nav_ChangePage"></hex:nav>
	<input id="hidSelectedRows" type="hidden" name="hidSelectedRows" runat="server">
	<input id="hidSelectedRowsForDrag" type="hidden" value="" />
	<asp:dropdownlist id="hidSelectedRowsAndNames" visible="False" runat="server"></asp:dropdownlist>
	<div id="TotalsContainer" runat="server" visible="false">
	<table width="100%">
		<tr>
			<td class="CustomFieldSectionCell" width="100%">
				<frm:FormSection id="CustomFieldGridSection" IsExpanded="True" ImageURL="" runat="server">
					<cfTotals:Grid id="CFTotalsGrid" runat="server" Visible="True" />
				</frm:FormSection>
			</td>
			<td class="CustomFieldSectionCell" width="100%">
				<frm:FormSection id="CustomFieldChartSection" IsExpanded="True" ImageURL="" runat="server" SectionWidth="410">
					<cfTotals:Chart id="CFTotalsChart" runat="server" Visible="True"/>
				</frm:FormSection>
			</td>
		</tr>			
	</table>
</div>
</asp:panel>
0
Veli
Telerik team
answered on 06 Jan 2012, 03:01 PM
Hi Jonathan,

If you are upgrading from RadControls Classic (for ASP.NET) to RadControls for ASP.NET AJAX, note that these are 2 completely different suites. The newer has been built on top of the Microsoft AJAX client-side platform and uses a different convention for building, associating and finding client components. AJAX uses $find() to access client components on the page. The <%= %> code expression is an AJAX-independent ASP.NET specific syntax. You've been using that with the older RadControls for ASP.NET too:

window['grid_' + '<%=grd.ClientID%>'];

You keep using the same expressions with $find too:

$find'<%=grd.ClientID%>');

So, the change in the approach for finding the client component by no means affects the usage of <% %> in your page. This means the exception you have reported to be getting cannot be caused by changing window['grid_' + '<%=grd.ClientID%>']; to $find('grid_' + '<%=grd.ClientID%>');

As for the RadGrid migration help topic you are probably referring to, please, let us know what information exactly you find not helpful, so that we can improve our documentation.

Veli
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
Tags
Ajax
Asked by
Jonathan
Top achievements
Rank 1
Answers by
Veli
Telerik team
Jonathan
Top achievements
Rank 1
Jayesh Goyani
Top achievements
Rank 2
Share this question
or