[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Cannot load a drag and drop item

Posted on 2010-08-17
14
Medium Priority
?
710 Views
Last Modified: 2013-11-27
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

0
Comment
Question by:lrbrister
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 7
14 Comments
 
LVL 96

Expert Comment

by:Bob Learned
ID: 33454013
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
 

Author Comment

by:lrbrister
ID: 33454126
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
 
LVL 96

Expert Comment

by:Bob Learned
ID: 33454354
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
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 

Author Comment

by:lrbrister
ID: 33454359
TheLearnedOne:
Yeah...I'm banging away and will pass along the code when I figure it out...hopefully
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 33454369
Did you try moving the LoadControl before the FindControl call?
0
 

Author Comment

by:lrbrister
ID: 33454484
TheLearnedOne
yeah...I've moved this stuff all over the place.  I know I'm missing something right in front of my face.
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 33454511
What should "e.HtmlElementID" reference?
0
 

Author Comment

by:lrbrister
ID: 33454658
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
 

Author Comment

by:lrbrister
ID: 33454706
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
 
LVL 96

Expert Comment

by:Bob Learned
ID: 33456031
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
 

Author Comment

by:lrbrister
ID: 33459367
TheLearnedOne:
ok...how do I fully qualify the iD?
0
 
LVL 96

Accepted Solution

by:
Bob Learned earned 2000 total points
ID: 33460364
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
 
LVL 96

Assisted Solution

by:Bob Learned
Bob Learned earned 2000 total points
ID: 33460366
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
 

Author Closing Comment

by:lrbrister
ID: 33475836
This put me on the right track and is definately workable.  Thanks...as always.
0

Featured Post

Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question