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

Dynamic population of tree after postback causes JS error

5 Answers 186 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Kalle
Top achievements
Rank 1
Kalle asked on 10 Apr 2008, 12:02 PM
Hi, !'m building a web app that contains a Prometheus TreeView with partial loading threw ServerSideCallback.
The tree view's data source can be changed by the user threw a dropdown. The Treeview's datasource and DataBinding is done in the OnPreRender event so that the newly selected value in the dropdown are cought (so that we don't get PostBack problem returning the earlier selected value).

The TreeView control works fine the first time the page is loaded, but when the user selects a new value ( = Datasource ) in the drop down, trigging a Postback I get this error :
 
Sys.InvalidOperationException: A control is already associated with the element.
http://localhost/ScriptResource.axd?d=I_sV7_5aqsHUuZz1dlHW-RqZsi4HVpivLZbDA9G0_dLCsiXBM93DwJPASsxTuNt_QVQWDeUc-OuHZjNgQ_3i5s507ruArCU5OS77T0Ea8jM1&t=633401439743849103
Line 7278
if (typeof(element.control) != 'undefined') throw Error.invalidOperation(Sys.Res.controlAlreadyDefined);


This worked fine with the old version of the TreeView. It seems that there are some conflicts when the page is PostBack and the ScriptManager doesn't clean the control cache or something. It should be Dissposed by the AJAX.NET framework.

I've tried clearing the ScriptManagers control collection in the OnInit and PreRender events but it didn't help.

The error dissapears when I set  EnableViewState="false" for the TreeView but then I loose all references so I can't load the child nodes and so on.

The code for loading the first nodes are

Protected

Overrides Sub OnPreRender(ByVal e As
LoadNodes()
MyBase.OnPreRender(e)
End Sub


Renders the nodes at the top level

Private

Sub LoadNodes()
RadTreeView.Nodes.Clear()
RadTreeView.ContextMenus.Add(GetContextMenues())
RadTreeView.DragAndDrop = True
For Each dr As DataRow In MigEl.DAL.Dimention.GetSingleTreeLevel(SelectedDimention(), 1, Nothing, GetSelectHierarcy()).Rows
Dim node As RadTreeNode = New RadTreeNode
node.Value = dr("Id").ToString()
node.Text = dr(
"Description").ToString()
node.Attributes.Add(
"RkId", dr("RkId").ToString())
node.ExpandMode = TreeNodeExpandMode.ServerSideCallBack
node.ContextMenuID =
"MemberMenu"
RadTreeView.Nodes.Add(node)
Next
RadTreeView.DataBind()
End Sub


'''

<summary>
''' Handles the NodeExpand event of the RadTreeView control.
''' </summary>
''' <param name="o">The source of the event.</param>
''' <param name="e">The <see cref="Telerik.WebControls.RadTreeNodeEventArgs" /> instance containing the event data.</param>

Protected Sub RadTreeView_NodeExpand(ByVal o As Object, ByVal e As RadTreeNodeEventArgs) Handles RadTreeView.NodeExpand

Dim level As Integer = If(e.Node Is Nothing, 0, e.Node.Level)
For Each dr As DataRow In MigEl.DAL.Dimention.GetSingleTreeLevel(SelectedDimention(), level + 2, e.Node.Value, GetSelectHierarcy()).Rows
Dim node As RadTreeNode = New RadTreeNode
node.Value = dr("Id").ToString()
node.Text = dr(
"Description").ToString()
node.Attributes.Add(
"RkId", dr("RkId").ToString())
node.ExpandMode = TreeNodeExpandMode.ServerSideCallBack
node.ContextMenuID =
"MemberMenu"
e.Node.Nodes.Add(node)
Next

End Sub

5 Answers, 1 is accepted

Sort by
0
Simon
Telerik team
answered on 14 Apr 2008, 01:46 PM
Hello Kalle,

This error may be caused by adding the same control twice on the page. For example, if your page derives from another one, it is possible that you add the control again in the derived page.

Please check this blog post on the matter: ASP.NET Ajax exception - Two components with the same id can't be added to the application.

I hope this helps.

Best wishes,
Simon
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Kalle
Top achievements
Rank 1
answered on 15 Apr 2008, 08:34 AM
That's correct, but as the post states, it's the control (treeview) that sould do the disposing call, not the caller of the control. Or am I reading it wrong?

I've tryed disposing the ScriptManager in the MasterPage's OnInit event and in the OnPreRender but without success.
ScriptManager1.Dispose()

If i'm to do the disposing where should I do it? and how?

Best regards
/Kalle
0
Simon
Telerik team
answered on 15 Apr 2008, 10:21 AM
Hi Kalle,

Could you open a formal support ticket and attach either a small running project or just the page where the error appears?

We will examine it thoroughly in order to pinpoint the exact cause of the error. Eventually, we will provide a solution or a workaround.

Thank you in advance for your cooperation.

Regards,
Simon
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Mark Hubert
Top achievements
Rank 1
answered on 16 Jul 2008, 01:26 PM
Hi Kalle / Telerik,

Did you find the cause for this problem, as I think I have the same problem.
I use telerik version: 2008.1.619.20 (error showed up also in 515).

Ter information:

I have a treeview in a combobox in a grid in a radwindow.
The grid is inside an ajax panel.
The treeview is populated dynamically at page load.

After an ajax call to the server on clicking a treenode in the treeview, the mentioned error (Two components with the same ID can not ...) appears.

I have tried all ajax configurations (radajax, msajax), and all the same error.
When I remove Ajax, the error does not show up.

An additional thing to mention is that the application runs in dotnetnuke.

Thanks in advance,

Mark
0
Simon
Telerik team
answered on 18 Jul 2008, 04:42 PM
Hello Mark van Zelst,

Please read this blog post describing the problem, its cause and resolution: ASP.NET Ajax exception - Two components with the same id can't be added to the application.

Regards,
Simon
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
Tags
TreeView
Asked by
Kalle
Top achievements
Rank 1
Answers by
Simon
Telerik team
Kalle
Top achievements
Rank 1
Mark Hubert
Top achievements
Rank 1
Share this question
or