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

Hierarchical Rad Grid and UserControl Error : Microsoft JScript runtime error: Sys.InvalidOperationException: A control is already associated with the element

1 Answer 94 Views
Grid
This is a migrated thread and some comments may be shown as answers.
ankool
Top achievements
Rank 1
ankool asked on 09 Dec 2008, 09:27 PM

Hi,

I have a 3 level hierarchical grid in page Grid.aspx. After expanding my grid to third level, I click on Add New Record, which opens a UserControl ( UsrCntrl1.ascx) as add template. This usercontrol contains a grid, a combo and a button (name is 'Add to grid') inside it.

In the usercontrol, when i select a value in the combobox  and click on button 'Add to Grid', a server side function is called which updates rad grid datatable by adding a new row to it and then binding the grid again. After the addition process is complete, the grid is successfully updated with new row, but when this usercontrol(UsrCntrl1.ascx) finishes its postback and rebinds itself to the 3 level hierarchical grid an error occurs saying,

"Microsoft JScript runtime error: Sys.InvalidOperationException: A control is already associated with the element."

The Grid UI Code in UsrCntrl.ascx:

 

 

<rad:RadGrid ID="DynamicList" runat="server" ></rad:RadGrid>

 

 

 

The Grid Codebehind Code in UsrCntrl.ascx.cs:

 

protected

 

void AddToList(object sender, ImageClickEventArgs e)

 

{

    DataTable

 

dt = new DataTable();

 

 

    if (Session["List"] == null)

 

    {

        dtPayee.Columns.Add(

"ABC", typeof(string));
        dtPayee.Columns.Add("XYZ", typeof(string));
    }
    else

 

        dt = (

DataTable)Session["List"];

 

 

 

    DataRow dr = dt.NewRow();

 

    dr[

"ABC"]= "Hello";
    dr[
"XYZ"]= "Bye";
    dt.Rows.Add(dr);

 

    DynamicList.DataSource = dt;

    DynamicList.DataBind();

    Session[

"List"] = dt;
}


What is causing this error ? I have already checked that there is no naming / ID conflicts between the grid page and template(usercontrol) page.

 

1 Answer, 1 is accepted

Sort by
0
Sebastian
Telerik team
answered on 12 Dec 2008, 03:23 PM
Hello ankool,

From your code I see that you are using simple data-binding for your grid with DataBind() calls. Does switching to advanced binding through the NeedDataSource event makes a difference? Note that features like data editing/insertion with custom edit forms require NeedDataSource binding as explained under the Description tab of this demo:

http://demos.telerik.com/aspnet-ajax/Grid/Examples/DataEditing/UserControlEditForm/DefaultCS.aspx

Best regards,
Sebastian
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
Grid
Asked by
ankool
Top achievements
Rank 1
Answers by
Sebastian
Telerik team
Share this question
or