5 Answers, 1 is accepted
0
                                Hello Aleks,
You could check the following blog post, where the issue you experience, is well described.
Greetings,
Nencho
the Telerik team
                                        You could check the following blog post, where the issue you experience, is well described.
Greetings,
Nencho
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
                                
                                                    Aleks
                                                    
                                            
    Top achievements
    
            
                
                Rank 1
            
    
                                                
                                                answered on 11 Jul 2012, 02:20 PM
                                            
                                        Thanks for your reply, but this post doesn't touch my problem even if it describes the same error message.
I had created test page to demonstrate the issue.
Default.aspx code:
 
Default.aspx.cs code:
 
 
 
 
 
 
 
 
The logic is next:
- When page loads in first time - we create one RadComboBox inside PlaceHolder and add it to the list stored in Session.
- When user click button - in async request we add one more RadComboBox inside PlaceHolder and add it to the list stored in Session.
- I got this error ("RegisterRequiresControlState can only be called before and during PreRender") inside RestoreControls method.
Where i'm doing wrong?
                                        I had created test page to demonstrate the issue.
Default.aspx code:
<%@ Page Title="Home Page" Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs"    Inherits="DynamicRadComboBoxes._Default" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head id="Head1" runat="server">    <title></title></head><body>    <form id="form1" runat="server">    <telerik:RadScriptManager ID="RadScriptManager1" runat="server" AsyncPostBackTimeout="1024">    </telerik:RadScriptManager>    <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">        <AjaxSettings>            <telerik:AjaxSetting AjaxControlID="pnlOnlineBookingContent">                <UpdatedControls>                    <telerik:AjaxUpdatedControl ControlID="pnlOnlineBookingContent" LoadingPanelID="ralpOnlineBooking" />                </UpdatedControls>            </telerik:AjaxSetting>        </AjaxSettings>    </telerik:RadAjaxManager>    <telerik:RadAjaxLoadingPanel runat="server" ID="ralpOnlineBooking" Skin="Default">    </telerik:RadAjaxLoadingPanel>    <div>        <asp:Panel runat="server" ID="pnlOnlineBookingContent">            <asp:PlaceHolder runat="server" ID="phSearchItems" />            <div style="clear: both;">            </div>            <br />            <asp:Panel runat="server" ID="pnlAddMoreService">                <div>                    <asp:LinkButton runat="server" ID="btnAddItem" Visible="true" OnClick="btnAddItem_Click">                        Add More Service                    </asp:LinkButton>                </div>            </asp:Panel>        </asp:Panel>    </div>    </form></body></html>Default.aspx.cs code:
using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;using Telerik.Web.UI;using System.IO;namespace DynamicRadComboBoxes{    public partial class _Default : System.Web.UI.Page    {        public List<RadComboBox> SearchItems        {            get { return (List<RadComboBox>)Session["SearchItems"]; }            set { Session["SearchItems"] = value; }        }        protected void Page_Init(object sender, EventArgs e)        {            if (Page.IsPostBack)                RestoreControls();        }        protected void Page_Load(object sender, EventArgs e)        {            if (!Page.IsPostBack)                ConfigureControls();        }        private void ConfigureControls()        {            SearchItems = new List<RadComboBox>();            CreateComboBox();        }        private void RestoreControls()        {            foreach (var combo in SearchItems)                phSearchItems.Controls.Add(combo);        }        private void CreateComboBox()        {            var combo = new RadComboBox();            combo.ID = string.Format("cboTest_{0}", Path.GetFileNameWithoutExtension(Path.GetTempFileName()));            SearchItems.Add(combo);            phSearchItems.Controls.Add(combo);        }        protected void btnAddItem_Click(object sender, EventArgs e)        {            CreateComboBox();        }    }}The logic is next:
- When page loads in first time - we create one RadComboBox inside PlaceHolder and add it to the list stored in Session.
- When user click button - in async request we add one more RadComboBox inside PlaceHolder and add it to the list stored in Session.
- I got this error ("RegisterRequiresControlState can only be called before and during PreRender") inside RestoreControls method.
0
                                Accepted
Hello Aleks,
As we consider transferring data, storing objects in session is not a good approach. You could simply store the ID's of the newly added controls, and recreate them when necessary. Please find the attached sample, where you could observe the implemented approach.
Kind regards,
Nencho
the Telerik team
                                        As we consider transferring data, storing objects in session is not a good approach. You could simply store the ID's of the newly added controls, and recreate them when necessary. Please find the attached sample, where you could observe the implemented approach.
Kind regards,
Nencho
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
                                
                                                    Roukaya
                                                    
                                            
    Top achievements
    
            
                
                Rank 2
            
    
                                                
                                                answered on 04 Aug 2012, 07:44 AM
                                            
                                        thanks  Nencho for your helpful example , exactly what i was looking for , 
but this sample allow us to restore comboboxes without their datasource , (they are restored empty)..
any way to restore filled combobox ??
thanks in advance ..
                                        but this sample allow us to restore comboboxes without their datasource , (they are restored empty)..
any way to restore filled combobox ??
thanks in advance ..
0
                                Hi Aleks,
Try to add the new RadComboBox control to the PlaceHolder immediately after its creation. After that you could bind the data to RadComboBox and the selection will persist through the postback. Please alter the CreateComboBox() method in a following manner:
 
 
 
In addition, please find the slightly modified sample attached.
Kind regards,
Nencho
the Telerik team
                                        Try to add the new RadComboBox control to the PlaceHolder immediately after its creation. After that you could bind the data to RadComboBox and the selection will persist through the postback. Please alter the CreateComboBox() method in a following manner:
private void CreateComboBox()   {       var combo = new RadComboBox();       phSearchItems.Controls.Add(combo);       combo.ID = string.Format("cboTest_{0}", Path.GetFileNameWithoutExtension(Path.GetTempFileName()));       combo.Items.Add(new RadComboBoxItem("item1", "1"));       combo.Items.Add(new RadComboBoxItem("item2", "2"));       combo.Items.Add(new RadComboBoxItem("item3", "3"));       SearchItemsIDs.Add(combo.ID);   }In addition, please find the slightly modified sample attached.
Kind regards,
Nencho
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.
