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

2 posts, 0 answers
  1. ankool
    ankool avatar
    50 posts
    Member since:
    Apr 2007

    Posted 09 Dec 2008 Link to this post


    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:




    void AddToList(object sender, ImageClickEventArgs e)





    dt = new DataTable();



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




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


            dt = (





        DataRow dr = dt.NewRow();



    "ABC"]= "Hello";
    "XYZ"]= "Bye";


        DynamicList.DataSource = dt;



    "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.


  2. Sebastian
    Sebastian avatar
    9934 posts

    Posted 12 Dec 2008 Link to this post

    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:


    Best regards,
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Back to Top