I have created radgrid and binded with dynamic columns from a datatable. I created even the edit column dynamically.But while clicking on edit i am getting this error."An Error has Occured because a control with id 'rgschedulegrid$ct100$ct104$EditButton' Could not be located or a different controls is assigned to the same ID after postback .If the ID is not assigned ,explicitly set the ID property of the controls that raise postback events to avoid this error"
Thanks & Regards,
Imthiyas Ahamed.A
11 Answers, 1 is accepted
Can you please provide more details about how and in which point of page's lifecycle RadGrid is created, some code snippets will be appreciated too. Also please refer to this help topics on how to create RadGrid programmatically.
Sincerely yours,
Rosen
the Telerik team
Check out Telerik Trainer , the state of the art learning tool for Telerik products.

I have the same problem. Did you have a solution?
Regrads
Markus

I have prepared a simple working project in order to reproduce the behavior you are describing but to no avail. I am attaching the page for your reference. Please let me know if you manage to reproduce what you are getting in this project and what steps to follow, so that we can test it too.
Regards,
Pavlina
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.

I still have the same problem. I am programmatically trying to create a RadGrid columns based on a configuration file. The grid display the columns and rows fine but I get an error when I click on the update column. Here is the code that creates the columns in code behind
------------------------------
this.RadGrid1.MasterTableView.
GridBoundColumn boundColumn;
boundColumn = new GridBoundColumn();
this.RadGrid1.MasterTableView.
boundColumn.DataField = "UserID;
boundColumn.HeaderText = "UserID;
boundColumn = new GridBoundColumn();
this.RadGrid1.MasterTableView.
boundColumn.DataField = "UserName;
boundColumn.HeaderText = "UserName;
GridEditCommandColumn editColumn = new GridEditCommandColumn();
editColumn.ButtonType = GridButtonColumnType.
editColumn.UniqueName = "EditCommandColumn";
this.RadGrid1.MasterTableView.
this.RadGrid1.MasterTableView.
------------------------------
Here is the code for the relevant part of the aspx page
------------------------------
<telerik:RadGrid ID="RadGrid1" runat="server" AllowAutomaticUpdates="True" AutoGenerateColumns="False" OnUpdateCommand="RadGrid1_
<MasterTableView AllowMultiColumnSorting="true" GroupLoadMode="Client" CommandItemDisplay="Top" EditMode="InPlace">
<EditFormSettings>
<EditColumn UniqueName="EditCommandColumn" ButtonType="ImageButton" />
</EditFormSettings>
</MasterTableView>
</telerik:RadGrid>
------------------------------
but now when I click on the update button I get this error
"Microsoft JScript runtime error: Sys.WebForms.
Do you have any sample code that I can look at to see how to update/add/delete rows in radgrid programmatically. Please assist.
Thank you.

I was able to make it work but by also creating the Grid programmatically and doing it at the Page_Init event.
Please have in mind that columns should be added to the corresponding collection first, before the values for their properties are set. To avoid this error you should change your code as shown below:
C#:
this
.RadGrid1.MasterTableView.Columns.Clear();
GridBoundColumn boundColumn;
boundColumn =
new
GridBoundColumn();
this
.RadGrid1.MasterTableView.Columns.Add(boundColumn);
boundColumn.DataField = "UserID;
boundColumn.HeaderText = "UserID;
boundColumn =
new
GridBoundColumn();
this
.RadGrid1.MasterTableView.Columns.Add(boundColumn);
boundColumn.DataField = "UserName;
boundColumn.HeaderText = "UserName;
GridEditCommandColumn editColumn =
new
GridEditCommandColumn();
this
.RadGrid1.MasterTableView.Columns.Add(editColumn);
editColumn.ButtonType = GridButtonColumnType.ImageButton;
editColumn.UniqueName =
"EditCommandColumn"
;
this
.RadGrid1.MasterTableView.DataKeyNames =
new
string
[1] {
"UserID"
};
You can review this help article for more information.
All the best,
Pavlina
the Telerik team

I Have faced a problem with my radgrid. My requirement I have a column which is was showing its cell value dynamically in some condition its show a radbutton and in other condition its show a lable value but the column type is GridBoundColumn. Everything is working fine but when I do selection changed from outside radcombobox to filter data in radgrid the error :
Microsoft JScript runtime error: Sys.WebForms.PageRequestManagerServerErrorException: An error has occurred because a control with id 'ctl00$ContentPlaceHolder1$rgOrderDetails$ctl00$ctl04$ctl02' could not be located or a different control is assigned to the same ID after postback. If the ID is not assigned, explicitly set the ID property of controls that raise postback events to avoid this error.
I have populate radgrid from my codebehind with rgOrderDetail.Datasource = dtSet;
And set column cell (either its RadButton/Lable) in rgOrderDetail_ItemDataBound. The code is :
protected void rgOrderDetails_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
{
if (e.Item.ItemType == Telerik.Web.UI.GridItemType.Item || e.Item.ItemType == Telerik.Web.UI.GridItemType.AlternatingItem)
{
string cellText = string.Empty;
foreach (TableCell cell in e.Item.Cells)
{
if (e.Item.Cells.GetCellIndex(cell) == 8)
{
if (cell.Text.Trim() == null || cell.Text.Trim() == string.Empty || cell.Text.Trim() == " " || cell.Text.Trim() == "I")
{
RadButton btnComplete = new RadButton();
//cell.Controls.Add(btnComplete);
btnComplete.Width = Unit.Pixel(101);
btnComplete.Height = Unit.Pixel(29);
btnComplete.Text = "Complete";
btnComplete.CssClass = "complete_button";
btnComplete.HoveredCssClass = "goButtonClassHov";
btnComplete.Image.ImageUrl = "Images/cb_empty_Green.png";
btnComplete.Image.IsBackgroundImage = true;
btnComplete.CommandName = "Complete";
btnComplete.Attributes.Clear();
cell.Controls.Add(btnComplete);
cellText = string.Empty;
}
else
{
Label lblRecommendText = new Label();
lblRecommendText.Text = "Completed";
lblRecommendText.BackColor = System.Drawing.Color.Transparent;
cell.Controls.Add(lblRecommendText);
}
}
}
}
}
And another thing I have an another grid with same logic is fire but the sorting not properly. Is there is any data problem. to sort this column.
I am sending my screen sort.
Thanks.
Chandan
This error is mostly caused by broken ViewState due to the dynamic creation of some control. As this article describes you need to recreate the controls on every page postback, not only on initial load.
Apply these suggestions on your project and check whether the issue is resolve.
In order to help I need further information about the sorting problem, please elaborate a bit more what is the exact problem, when is happening what is causing it and similar information.
All the best,
Andrey
the Telerik team

Thanks for your reply but sorry to give you late answer.
I've tried with your suggestion but I can not understand the approach.
My requirment :
I have RadGrid where data is binding from page load.
And in RadGrid ItemDataBound there is some manupulation in a column called Status I was add some cells are Button and some cells are label.
And filter the data on that column with a RadCombobox Items (All/Complete/Incomplete).
Everything is fine accept Items (All/Incomplete) working fine but when I select "Complete" there is a javascript error and page is break and filter not happning.
The code is like this:
protected void Page_Load(object sender, EventArgs e)
{
rgOrderDetails.DataSource = serviceOrder.LoadData(connection);
rgOrderDetails.DataBind();
}
protected void rgOrderDetails_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
{
{
if (cell.Text.Trim() == null || cell.Text.Trim() == string.Empty || cell.Text.Trim() == " " || cell.Text.Trim() == "I")
{
RadButton btnComplete = new RadButton();
cell.Controls.Add(btnComplete);
btnComplete.Width = Unit.Pixel(101);
btnComplete.Height = Unit.Pixel(29);
btnComplete.Text = "Complete";
btnComplete.CssClass = "complete_button";
btnComplete.HoveredCssClass = "goButtonClassHov";
btnComplete.Image.ImageUrl = "Images/cb_empty_Green.png";
btnComplete.Image.IsBackgroundImage = true;
btnComplete.CommandName = "Complete";
btnComplete.Attributes.Clear();
}
else
{
Label lblRecommendText = new Label();
lblRecommendText.Text = "Completed";
lblRecommendText.BackColor = System.Drawing.Color.Transparent;
cell.Controls.Add(lblRecommendText);
}
}
{
rgOrderDetails.DataSource = serviceOrder.LoadData(connection);
rgOrderDetails.DataBind();
}
Error is :
Microsoft JScript runtime error: Sys.WebForms.PageRequestManagerServerErrorException: An error has occurred because a control with id 'ctl00$ContentPlaceHolder1$rgOrderDetails$ctl00$ctl04$ctl02' could not be located or a different control is assigned to the same ID after postback. If the ID is not assigned, explicitly set the ID property of controls that raise postback events to avoid this error.
I will send you the screen shot of my page also.
Thnaks
Chandan
Please modify your code in compliance with this help article. As this help article says you should use advanced data binding when you are using advanced features or RadGrid like paging, filtering,sorting and so on.
Additionally, you could check this help article for an overview of what you need to know when you are manipulating the structure of RadGrid dynamically. Basically it is always better to add controls statically and then just change their properties in order to fit your needs. Like if you want some control only to appear in a response to some action it is better to change its visible property when this action is performed rather than add it and remove it every time. Very useful article about dynamic controls could be found in the Infinities loop blog.
So, in conclusion it is better to move out your logic for adding buttons to RadGrid from the ItemDataBound event to some other event(for example Page_Load or Page_Init) or to declare it statically in ASPX file. The error you are receiving is most probably caused by this line of code:
cell.Controls.Add(btnComplete);
This statement is executed on every Page reload and because it is trying to add an already added control to the page the framework is raising the exception.
Apply these suggestion to your project and check whether the issue is resolved.
Kind regards,
Andrey
the Telerik team