Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / ASP.NET > Ajax > The control collection cannot be modified during DataBind, Init, Load, PreRender or Unload phases.
RadControls for ASP.NET are no longer supported (see this page for reference). In case you have inquiries about the Telerik ASP.NET AJAX controls, post them in the pertinent ASP.NET AJAX forums.

Not answered The control collection cannot be modified during DataBind, Init, Load, PreRender or Unload phases.

Feed from this thread
  • Aaron Gravois avatar

    Posted on Feb 15, 2011 (permalink)

    I'm trying to set some Session variables that will be used in binding some RadGrids on button click.  I have ajaxified the button to update the panel that the grids are located in, and i get the following error on the first time that I click the button:
    "The control collection cannot be modified during DataBind, Init, Load, PreRender or Unload phases."

    At that point, if I refresh the page and click the button again, it works fine.  I think it's because I'm trying to set Session variables that will be used in databinding, which is possibly trying to happen while the Session variables are being set.  I'm not quite sure though...

    Here is my markup:
    <telerik:RadScriptManager ID="RadScriptManager1" runat="server">
            </telerik:RadScriptManager>
            <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
                <AjaxSettings>
                    <telerik:AjaxSetting AjaxControlID="calcButton">
                        <UpdatedControls>  
                            <telerik:AjaxUpdatedControl ControlID="panel1" LoadingPanelID="RadAjaxLoadingPanel1" />                                               
                        </UpdatedControls>
                    </telerik:AjaxSetting>
                </AjaxSettings>       
            </telerik:RadAjaxManager>
            <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server" Skin="WebBlue" />
            <center>
                <table>
                    <tr>
                        <td align="right">   
                            <asp:Label ID="yearLabel" runat="server" Text="Select Year:" Font-Bold="true" Font-Size="Medium"></asp:Label>
                        </td>
                        <td> </td>
                        <td align="left">
                            <telerik:RadComboBox ID="yearList" runat="server" DataSourceID="yearSource" DataTextField="year" DataValueField="year"></telerik:RadComboBox>
                        </td>
                    </tr>
                    <tr>
                        <td align="right">
                            <asp:Label ID="monthLabel" runat="server" Text="Select 4-5-4 Month:" Font-Bold="true" Font-Size="Medium"></asp:Label>
                        </td>
                        <td> </td>
                        <td align="left">
                            <telerik:RadComboBox ID="monthList" runat="server">
                                <Items>                               
                                    <telerik:RadComboBoxItem Text="January" Value="1" />
                                    <telerik:RadComboBoxItem Text="February" Value="2" />
                                    <telerik:RadComboBoxItem Text="March" Value="3" />
                                    <telerik:RadComboBoxItem Text="April" Value="4" />
                                    <telerik:RadComboBoxItem Text="May" Value="5" />
                                    <telerik:RadComboBoxItem Text="June" Value="6" />
                                    <telerik:RadComboBoxItem Text="July" Value="7" />
                                    <telerik:RadComboBoxItem Text="August" Value="8" />
                                    <telerik:RadComboBoxItem Text="September" Value="9" />
                                    <telerik:RadComboBoxItem Text="October" Value="10" />
                                    <telerik:RadComboBoxItem Text="November" Value="11" />
                                    <telerik:RadComboBoxItem Text="December" Value="12" />               
                                </Items>
                            </telerik:RadComboBox>       
                        </td>
                    </tr>
                     <tr>
                        <td align="right">   
                            <asp:Label ID="accountLabel" runat="server" Text="Select Account:" Font-Bold="true" Font-Size="Medium"></asp:Label>
                        </td>
                        <td> </td>
                        <td align="left">
                            <telerik:RadComboBox NoWrap="true" ID="accountBox" runat="server" DataSourceID="accountSource" DataTextField="description" DataValueField="account" Width="250px"></telerik:RadComboBox>
                        </td>
                    </tr>
                    <tr>
                        <td align="center" colspan="3">
                            <asp:Button ID="calcButton" runat="server" Text="Calculate GL Balance" style="cursor:pointer" OnClick="calcButton_Click"/>
                        </td>
                    </tr>
                </table>
                <br />
                <br />
            </center>
             
                <asp:Button ID="hiddenButton" runat="server" style="display:none" OnClientClick="return false();" />
                <asp:Panel ID="panel1" runat="server" DefaultButton="hiddenButton">
                <table>
                    <tr>
                        <td align="right">
                            <asp:Label ID="accountText" runat="server" Text="Account: " Font-Bold="true"></asp:Label>
                        </td>
                        <td align="left">
                            <asp:Label ID="accountValue" runat="server"></asp:Label>
                        </td>
                    </tr>
                    <tr>
                        <td align="right">
                            <asp:Label ID="GLCodeText" runat="server" Text="GL Code: " Font-Bold="true"></asp:Label>
                        </td>
                        <td align="left">
                            <asp:Label ID="GLCodeValue" runat="server"></asp:Label>
                        </td>
                    </tr>
                    <tr>
                        <td align="right">
                            <asp:Label ID="dateStartText" runat="server" Text="4-5-4 Start Date: " Font-Bold="true"></asp:Label>
                        </td>
                        <td align="left">
                            <asp:Label ID="dateStartValue" runat="server"></asp:Label>
                        </td>
                    </tr>
                    <tr>
                        <td align="right">
                            <asp:Label ID="dateEndText" runat="server" Text="4-5-4 End Date: " Font-Bold="true"></asp:Label>
                        </td>
                        <td align="left">
                            <asp:Label ID="dateEndValue" runat="server"></asp:Label>
                        </td>
                    </tr>              
                    </table>
                    <center>
                        <table>
                        <tr>
                            <td colspan="2" align="center">
                                 <telerik:RadTabStrip ID="RadTabStrip1" runat="server" Orientation="HorizontalTop" SelectedIndex="0" MultiPageID="RadMultiPage1">
                                    <Tabs>
                                        <telerik:RadTab Text="Balance View"></telerik:RadTab>
                                        <telerik:RadTab Text="Outstanding Entries"></telerik:RadTab>
                                        <telerik:RadTab Text="Entries During"></telerik:RadTab>
                                        <telerik:RadTab Text="Entries After"></telerik:RadTab>
                                        <telerik:RadTab Text="Voids and Modifications"></telerik:RadTab>
                                    </Tabs>
                                </telerik:RadTabStrip>
                                <telerik:RadMultiPage ID="RadMultiPage1" runat="server" SelectedIndex="0">
                                    <telerik:RadPageView ID="balancePage" runat="server">This is the Balance Page
                                    </telerik:RadPageView>
                                    <telerik:RadPageView ID="outstandingPage" runat="server">
                                        <telerik:RadGrid ID="outstandingGrid" ShowStatusBar="true" DataSourceID="outstandingSource" AllowFilteringByColumn="true" ShowFooter="true" 
                                            runat="server" AutoGenerateColumns="true" PageSize="20" AllowSorting="True" AllowMultiRowSelection="False"  EnableLinqExpressions="false"
                                            AllowPaging="True" GridLines="Vertical" ShowHeader="true" Skin="WebBlue" AlternatingItemStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center" HeaderStyle-HorizontalAlign="Center"
                                            FilterItemStyle-HorizontalAlign="Center">       
                                        </telerik:RadGrid>
                                    </telerik:RadPageView>
                                    <telerik:RadPageView ID="duringPage" runat="server">This is the During Page
                                    </telerik:RadPageView>
                                    <telerik:RadPageView ID="afterPage" runat="server">This is the After Page
                                    </telerik:RadPageView>
                                    <telerik:RadPageView ID="voidsPage" runat="server">This is the Voids Page
                                    </telerik:RadPageView>
                                </telerik:RadMultiPage>
                            </td>
                        </tr>
                    </table>  
                </center>
                </asp:Panel>
                 
             
     
        <asp:SqlDataSource ID="yearSource" ConnectionString="<%$ ConnectionStrings:StoreMainConnectionString %>"
            SelectCommand="select distinct year(statement_date) as year from storemain..statement_header"
            runat="server">
        </asp:SqlDataSource>
     
         
        <asp:SqlDataSource ID="accountSource" ConnectionString="<%$ ConnectionStrings:DBMotoConnectionString %>"
            SelectCommand="select ccbact as account, ccadsc as description  from dbmoto..xachkcp where ccactv <> 'I' and ccbact <> ''"
            runat="server">
        </asp:SqlDataSource>
     
        <asp:SqlDataSource ID="outstandingSource" ConnectionString="<%$ ConnectionStrings:DBMotoConnectionString %>"
            SelectCommand="select crbact, crcamt, crciso, crpaye from dbmoto..xachkrp where crbact = @account and crciso < @startDate and crcsts <> 'R'"
            runat="server">
            <SelectParameters>
                <asp:SessionParameter Name="account" SessionField="account" />
                <asp:SessionParameter Name="startDate" SessionField="startDate" />
            </SelectParameters>
        </asp:SqlDataSource>   

    And here is my code behind for my button click:
    protected void calcButton_Click(object sender, EventArgs e)
    {
        KeyValuePair<string, string> dates = Balance.GetDates(monthList.SelectedValue, yearList.SelectedValue);
        Session["startDate"] = dates.Key;
        Session["endDate"] = dates.Value;
        Session["account"] = accountBox.SelectedValue;
        string GLCode = Balance.GetGLCode(accountBox.SelectedValue);
        accountValue.Text = accountBox.SelectedValue;
        GLCodeValue.Text = GLCode;
        dateStartValue.Text = dates.Key;
        dateEndValue.Text = dates.Value;       
    }


    Any ideas?

    Thanks,
    Aaron

  • Aaron Gravois avatar

    Posted on Feb 16, 2011 (permalink)

    UPDATE:

    I fixed my issue.  It had something to do with auto generating the columns.  I had the columns auto generated for testing purposes.  Once I defined each column, the error went away.

    Thanks,
    Aaron

Back to Top

Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / ASP.NET > Ajax > The control collection cannot be modified during DataBind, Init, Load, PreRender or Unload phases.