Cannot load a drag and drop item

My attached HTML and vb code works for the drag and drop Telerik radListBox.
If I drag an item onto the page into a panel...it loads fine.

However...
If I drag onto a panel that ALREADY has an item dropped on it...I error out with this error message.

I suspect it's because the control has been rendered with a new ID maybe?
I also tried placing parts of the vb inside the page load  If Not IsPostback code...same error

====================================================================
Error message when I drop on an existing populated panel
====================================================================

Line 27:         _controlNew = LoadControl(e.SourceDragItems.Item(0).Value)
Line 28:         Dim p As Panel = Page.FindControl(e.HtmlElementID.ToString())
Line 29:         p.Controls.Add(_controlNew)
Line 30:         p.Attributes.Add("userControlID", e.SourceDragItems.Item(0).Value)
Line 31:     End Sub
 

Source File: C:\Development\DragAndDrop\test.aspx.vb    Line: 29

Stack Trace:

==================================================
HTML
==================================================

 <div>
        <telerik:RadListBox ID="RadListBox2" runat="server" Width="200px" Height="200px"
            CssClass="fl" SelectionMode="Single" TransferToID="RadListBox2" AllowReorder="true"
            EnableDragAndDrop="true" OnDropped="RadListBox2_Dropped">
            <Items>
                <telerik:RadListBoxItem Text="USA" />
                <telerik:RadListBoxItem Text="Add Chart TL" Value="chart.ascx" />
                <telerik:RadListBoxItem Text="Add Chart TR" Value="chart.ascx" />
                <telerik:RadListBoxItem Text="Add Chart BL" Value="chart.ascx" />
                <telerik:RadListBoxItem Text="Add Chart BR" Value="chart.ascx" />
            </Items>
        </telerik:RadListBox>
        <asp:TextBox ID="TextBox1" runat="server" Wrap="true" Rows="3" TextMode="MultiLine"></asp:TextBox>
        <table cellpadding="0" cellspacing="0" border="1" style="margin: 0 Auto; padding-top: 20px;
            border: solid 1px gray; height: 600px; width: 800px;">
            <tr>
                <td align="center" valign="middle">
                    <asp:Panel ID="TopLeft" runat="server" Height="300px" Width="400px">
                    </asp:Panel>
                </td>
                <td align="center" valign="middle">
                    <asp:Panel ID="TopRight" runat="server" Height="300px" Width="400px">
                    </asp:Panel>
                </td>
            </tr>
            <tr>
                <td align="center" valign="middle">
                    <asp:Panel ID="BottomLeft" runat="server" Height="300px" Width="400px">
                    </asp:Panel>
                </td>
                <td align="center" valign="middle">
                    <asp:Panel ID="BottomRight" runat="server" Height="300px" Width="400px">
                    </asp:Panel>
                </td>
            </tr>
        </table>
    </div>


====================================================
VB CODE
=====================================================
 Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim containers As ArrayList = New ArrayList()
        containers.Add(TopLeft)
        containers.Add(TopRight)
        containers.Add(BottomLeft)
        containers.Add(BottomRight)
        For Each panelContainer As Panel In containers
            If panelContainer.Attributes("userControlID") <> Nothing Then
                Dim _controlNew As New Control
                _controlNew = LoadControl(panelContainer.Attributes("userControlID"))
                panelContainer.Controls.Add(_controlNew)
            End If
        Next
    End Sub

    Protected Sub RadListBox2_Dropped(ByVal sender As Object, ByVal e As Telerik.Web.UI.RadListBoxDroppedEventArgs)
        Dim _controlNew As New Control
        _controlNew = LoadControl(e.SourceDragItems.Item(0).Value)
        Dim p As Panel = Page.FindControl(e.HtmlElementID.ToString())
        p.Controls.Add(_controlNew)
        p.Attributes.Add("userControlID", e.SourceDragItems.Item(0).Value)
    End Sub

Open in new window

Larry Bristersr. DeveloperAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Bob LearnedCommented:
I don't see the error message text to explain that error.  My first inclination is to agree, and say that you can't have two controls with the same unique ID.
0
Larry Bristersr. DeveloperAuthor Commented:
TheLearnedOne:
Attached is a screenprint of the error in debug.
I have opened a support ticket at Telerik for this but am on a pretty solid timetable here and may not get a reply in time from them.

screenprint.jpg
0
Bob LearnedCommented:
I see where you are trying to use FindControl, but if you are trying to use FindControl to find a control that hasn't been loaded yet with LoadControl, then it won't find anything...
0
Fundamentals of JavaScript

Learn the fundamentals of the popular programming language JavaScript so that you can explore the realm of web development.

Larry Bristersr. DeveloperAuthor Commented:
TheLearnedOne:
Yeah...I'm banging away and will pass along the code when I figure it out...hopefully
0
Bob LearnedCommented:
Did you try moving the LoadControl before the FindControl call?
0
Larry Bristersr. DeveloperAuthor Commented:
TheLearnedOne
yeah...I've moved this stuff all over the place.  I know I'm missing something right in front of my face.
0
Bob LearnedCommented:
What should "e.HtmlElementID" reference?
0
Larry Bristersr. DeveloperAuthor Commented:
It is part of the controls class.
In the attached sub if I type ...
If e.....
What pops up is HtmlElementID and SourceDragItems
HtmlElementID is the control id of what is being dropped ON
And The SourceDragItems is where it's coming from (chart.ascx from my HTML above)
 

Protected Sub RadListBox2_Dropped(ByVal sender As Object, ByVal e As Telerik.Web.UI.RadListBoxDroppedEventArgs)
        Dim p As Panel = Page.FindControl(e.HtmlElementID.ToString())
        If Not p.Attributes("userControlID") Is Nothing Then
            p.Controls.RemoveAt(1)
        End If

        Dim _controlNew As New Control
        _controlNew = LoadControl(e.SourceDragItems.Item(0).Value)
        p.Controls.Add(_controlNew)
        p.Attributes.Add("userControlID", e.SourceDragItems.Item(0).Value)
    End Sub

Open in new window

0
Larry Bristersr. DeveloperAuthor Commented:
The Learned one..
So..The FIRST time I drop on (topleft) panel
In debug...the value of s in
Dim s As String = e.HtmlElementID.ToString() is "TopLeft"
The SECOND time I drop on it the value of s is ctl02_Chart1
I just can't seem to figure a way around this.
0
Bob LearnedCommented:
Depending on your control hierarchy, if e.HtmlElementID is not a fully-qualified unique ID, then FindControl can't find it.  FindControl only works within a naming container, unless you fully qualified the ID.
0
Larry Bristersr. DeveloperAuthor Commented:
TheLearnedOne:
ok...how do I fully qualify the iD?
0
Bob LearnedCommented:
Here is a crude example, using the RadListBox, RadScriptManager, and a user control with a RadChart:


Imports System.Web.UI
Imports System.Web.UI.HtmlControls
Imports System.Web.UI.WebControls

Partial Public Class _Default
    Inherits System.Web.UI.Page

    Private _chartList As Control(,)

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load
        If Not IsPostBack Then
            _chartList = New Control(1, 1) {}
            Session("ChartList") = _chartList
        Else
            _chartList = DirectCast(Session("ChartList"), Control(,))

            Me.LoadChartControls()
        End If
    End Sub

    Private Sub LoadChartControls()
        If _chartList(0, 0) IsNot Nothing Then
            Me.AddChartControl("TopLeft", _chartList(0, 0), Nothing)
        End If

        If _chartList(0, 1) IsNot Nothing Then
            Me.AddChartControl("TopRight", _chartList(0, 1), Nothing)
        End If

        If _chartList(1, 0) IsNot Nothing Then
            Me.AddChartControl("BottomLeft", _chartList(1, 0), Nothing)
        End If

        If _chartList(1, 1) IsNot Nothing Then
            Me.AddChartControl("BottomRight", _chartList(1, 1), Nothing)
        End If
    End Sub

    Protected Sub RadListBox2_Dropped(ByVal sender As Object, ByVal e As Telerik.Web.UI.RadListBoxDroppedEventArgs)
        Me.AddChartControl(e.HtmlElementID, Nothing, e.SourceDragItems(0).Value)
    End Sub

    Private Sub AddChartControl(ByVal panelId As String, ByVal control As Control, ByVal controlName As String)
        Dim table As HtmlTable = DirectCast(Page.FindControl("ChartTable"), HtmlTable)

        If control Is Nothing Then
            control = LoadControl(controlName)
        End If

        Dim row As Integer = 0
        Dim column As Integer = 0

        Select Case panelId

            Case "TopLeft"
                Exit Select

            Case "TopRight"
                column = 1
                Exit Select

            Case "BottomLeft"
                row = 1
                Exit Select

            Case "BottomRight"
                row = 1
                column = 1
                Exit Select
            Case Else

                Throw New InvalidOperationException("Unknown panel: " & panelId)
        End Select

        _chartList(row, column) = control

        Session("ChartList") = _chartList

        Dim panel As Panel = DirectCast(table.FindControl(panelId), Panel)
        panel.Controls.Add(control)
        panel.Attributes.Add("userControlID", controlName)

    End Sub

End Class

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Bob LearnedCommented:
HTML:


<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>

<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <telerik:RadScriptManager ID="RadScriptManager1" runat="server">
        </telerik:RadScriptManager>
        <telerik:RadListBox ID="RadListBox2" runat="server" Width="200px" Height="200px"
            CssClass="fl" SelectionMode="Single" TransferToID="RadListBox2" AllowReorder="true"
            EnableDragAndDrop="true" OnDropped="RadListBox2_Dropped">
            <Items>
                <telerik:RadListBoxItem Text="USA" />
                <telerik:RadListBoxItem Text="Add Chart" Value="chart.ascx" />
            </Items>
        </telerik:RadListBox>
        <asp:TextBox ID="TextBox1" runat="server" Wrap="true" Rows="3" TextMode="MultiLine"></asp:TextBox>
        <table cellpadding="0" cellspacing="0" border="1" style="margin: 0 Auto; padding-top: 20px;
            border: solid 1px gray; height: 600px; width: 800px;" runat="server" id="ChartTable">
            <tr>
                <td align="center" valign="middle">
                    <asp:Panel ID="TopLeft" runat="server" Height="300px" Width="400px">
                    </asp:Panel>
                </td><td align="center" valign="middle">
                    <asp:Panel ID="TopRight" runat="server" Height="300px" Width="400px">
                    </asp:Panel>
                </td>
            </tr>
            <tr>
                <td align="center" valign="middle">
                    <asp:Panel ID="BottomLeft" runat="server" Height="300px" Width="400px">
                    </asp:Panel>
                </td><td align="center" valign="middle">
                    <asp:Panel ID="BottomRight" runat="server" Height="300px" Width="400px">
                    </asp:Panel>
                </td>
            </tr>
        </table>
    </div>
    </form>
</body>
</html>

Open in new window

0
Larry Bristersr. DeveloperAuthor Commented:
This put me on the right track and is definately workable.  Thanks...as always.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.