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

[Solved] Second DataBind() fail in case of asynchronous task processing

1 Answer 213 Views
Grid
This is a migrated thread and some comments may be shown as answers.
David
Top achievements
Rank 1
David asked on 03 Jul 2009, 12:14 PM

Hi,
I'm porting our software to RadGrid component and I have following problem:

I'm bounding dataset to the Grid in function, which is called in asynchronous way. First call of .Rebind() or .DataBind() is successful. But after binding I'm changing some properties of the grid - e.g. width of grid columns, header text of grid columns etc. Then I'm trying to call .DataBind() (or .Rebind()) again - and this second call fail with error RegisterRequiresControlState can only be called before and during PreRender.

If I will not make the 2nd DataBind() call, then I will not see the visual changes, which I've done in async. task. Is it possible to somehow reshow the grid in async task?

I'm adding class code:

    public partial class _Default : System.Web.UI.Page  
    {  
        public delegate void AsyncMethodCaller();  
 
        private DataSet Data  
        {  
            get  
            {  
                return (DataSet)Session["Data"];  
            }  
        }  
 
        private void SetData()  
        {  
            OracleConnection conn = new OracleConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);  
 
            DataSet set = new DataSet();  
 
            OracleDataAdapter adapter = new OracleDataAdapter("select USER_ID, USER_NAME, FULL_NAME from USERS order by USER_ID", conn);  
            conn.Open();  
            adapter.Fill(set);  
            conn.Close();  
            conn.Dispose();  
 
            Session["Data"] = set;  
 
            BoundData();  
            RadGrid1.DataBind();  
 
            foreach (GridColumn col in RadGrid1.MasterTableView.AutoGeneratedColumns)  
            {  
                //some code  
                col.HeaderText = "*" + col.HeaderText;  
            }  
 
            BoundData();  
            RadGrid1.DataBind();  
        }  
 
        protected void Page_Load(object sender, EventArgs e)  
        {  
            if (!IsPostBack)  
            {  
                PageAsyncTask task = new PageAsyncTask(new BeginEventHandler(BeginGetAsyncData), new EndEventHandler(EndGetAsyncData), new EndEventHandler(TimeoutGetAsyncData), null);  
                RegisterAsyncTask(task);  
            }  
        }  
 
        protected IAsyncResult BeginGetAsyncData(Object src, EventArgs args, AsyncCallback cb, Object state)  
        {  
            AsyncMethodCaller caller = new AsyncMethodCaller(SetData);  
            return caller.BeginInvoke(cb, caller);  
        }  
 
        protected void EndGetAsyncData(IAsyncResult ar)  
        {  
            AsyncMethodCaller caller = (AsyncMethodCaller)ar.AsyncState;  
            caller.EndInvoke(ar);  
        }  
 
        protected void TimeoutGetAsyncData(IAsyncResult ar)  
        {  
            Response.Write("TimeOut!");  
        }  
 
        protected void RadGrid1_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e)  
        {  
            BoundData();  
        }  
 
        private void BoundData()  
        {  
            if (Data != null)  
            {  
                RadGrid1.DataSource = Data;  
                RadGrid1.DataMember = ((DataSet)RadGrid1.DataSource).Tables[0].TableName;  
            }  
        }  
 
        protected void btnExportExcel_Click(object sender, EventArgs e)  
        {  
            RadGrid1.MasterTableView.ExportToExcel();  
        }  
    }  
 

The grid is set to have AutoGenerated columns.

Please help,
  Ozon.

1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 06 Jul 2009, 08:15 AM
Hi David,

I have found one blog post which explains about this error. Go through it and see if it shed some light on this issue.
RegisterRequiresControlState Error + Workaround

Shinu
Tags
Grid
Asked by
David
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Share this question
or