Integrating Drag & Drop with Web Forms

E

Ed Dennison

I am trying to create a simple ASP.NET web page that includes a list
box into which my user can drag and drop URLs. I want the user to be
able to easily build a list of URLs by dragging and dropping links
from other pages onto my page (and also dragging the link from IE's
Address bar).

This is what my index.aspx file looks like (in HTML view):

<%@ Page language="c#" Codebehind="index.aspx.cs"
AutoEventWireup="false" Inherits="rdmgr.WebForm1" %>
<HTML>
<HEAD>
<title>WebForm1</title>
<SCRIPT language="javascript">
function SetText()
{
window.event.returnValue = false;
window.event.dataTransfer.dropEffect = "copy";
var opto = new Option(window.event.dataTransfer.getData("Text"));
window.document.Form1.Select1.add (opto);
}
function OverDrag()
{
window.event.returnValue = false;
}
</SCRIPT>
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<asp:Button id="Button1" style="Z-INDEX: 101; LEFT: 736px;
POSITION: absolute; TOP: 88px" runat="server"
Text="Button" Width="74px" Height="32px"></asp:Button>
<SELECT id="Select1" style="Z-INDEX: 103; LEFT: 160px; WIDTH:
480px; POSITION: absolute; TOP: 88px; HEIGHT: 280px"
size="17" name="Select1" runat="server" ondrop="SetText()"
ondragover="OverDrag()">
<OPTION></OPTION>
</SELECT>
</form>
</body>
</HTML>

The web page behaves exactly as I desire: when I drag links or URLs
into the list box, the link text is added to the list. Perfect.

The problem is, that from the point of view of the C# code, nothing is
inside the listbox. Specifically, when I handle the Click event for my
button, the Select1 object has no Items. Also, if I refresh the web
page, the list contents disappear. And finally, the
Select1_ServerChange event does not fire when I drag items into the
list.

I assume that I am missing some critical piece of glue that causes the
client side activity in the javascript function to get dispatched to
the server side. Can anyone tell me what I need to do?

Thank you!

Ed Dennison
E-mail: ed at cognex dot com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,082
Messages
2,570,589
Members
47,212
Latest member
JaydenBail

Latest Threads

Top