Oct 24, 2011, 8:11 PM
[CLOSED] Drag does not function after postback to UpdatePanel
I am using a DragZone on the page. The page also has an UpdatePanel. I am dragging an item from inside the UpdatePanel. On initial load, everything works fine. If the UpdatePanel updates then the drag will no longer work.
I have created a example based upon your DragDrop example 2. When the page is loaded you can drag and drop to your heart's content. After you press the "BigButton" and the update panel is refreshed, drag becomes impossible; the getDragData and the onInitDrag functions are never called.
Aspx Page:
I have created a example based upon your DragDrop example 2. When the page is loaded you can drag and drop to your heart's content. After you press the "BigButton" and the update panel is refreshed, drag becomes impossible; the getDragData and the onInitDrag functions are never called.
Aspx Page:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="DragProblem.aspx.cs" Inherits="CJLRDWeb.Tests.DragProblem" %>
<%@ Register assembly="Ext.Net" namespace="Ext.Net" tagprefix="ext" %>
<!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 id="Head1" runat="server">
<title>Drag&Drop - Ext.NET Examples</title>
<link href="../../../../resources/css/examples.css" rel="stylesheet" type="text/css" />
<style type="text/css">
body {
font-size: 11px;
font-family: arial;
}
.dd-ct {
position:relative;
border: 1px solid silver;
width: 180px;
height: 180px;
background-color: #ffffc0;
}
#dd1-ct {
left: 64px;
}
#dd2-ct {
left: 256px;
}
.dd-item {
height: 14px;
border: 1px solid #a0a0a0;
background-color: #c4d0ff;
vertical-align: middle;
cursor: move;
padding: 2px;
z-index: 1000;
margin: 2px;
}
.dd-ct .dd-item {
margin: 2px;
}
.dd-proxy {
opacity: 0.4;
-moz-opacity: 0.4;
filter: alpha(opacity=40);
}
.dd-over {
background-color: #ffff60;
}
</style>
<ext:ResourcePlaceHolder ID="ResourcePlaceHolder1" runat="server" Mode="ScriptFiles" />
<script type="text/javascript">
function getDragData(e) {
if (!this.ddel) {
this.ddel = document.createElement('div');
}
var target = Ext.get(e.getTarget());
if (target.hasClass('dd-ct')) {
return false;
}
return { ddel: this.ddel, item: target };
}
function onInitDrag(e) {
this.ddel.innerHTML = this.dragData.item.dom.innerHTML;
this.ddel.className = this.dragData.item.dom.className;
this.ddel.style.width = this.dragData.item.getWidth() + "px";
this.proxy.update(this.ddel);
}
function getRepairXY(e, data) {
data.item.highlight('#e8edff');
return data.item.getXY();
}
function notifyDrop(dd, e, data) {
this.el.removeClass(this.overClass);
this.el.appendChild(data.item);
return true;
}
</script>
</head>
<body>
<form id="Form1" runat="server">
<asp:ScriptManager ID="ScriptManagerMain" runat="server" EnablePartialRendering="true" EnablePageMethods="true" />
<ext:ResourceManager ID="ResourceManager1" runat="server" />
<a href="http://www.extjs.com/learn/Tutorial:Advanced_Custom_Drag_and_Drop_Part_2">Tutorial:Advanced Custom Drag and Drop Part 2</a>
<ext:DragZone ID="DragZone1" runat="server" Target="dd1-ct" Group="group" Scroll="false">
<GetDragData Fn="getDragData" />
<OnInitDrag Fn="onInitDrag" />
<GetRepairXY Fn="getRepairXY" />
</ext:DragZone>
<ext:DragZone ID="DragZone2" runat="server" Target="dd2-ct" Group="group" Scroll="false">
<GetDragData Fn="getDragData" />
<OnInitDrag Fn="onInitDrag" />
<GetRepairXY Fn="getRepairXY" />
</ext:DragZone>
<ext:DropTarget ID="DropTarget1" runat="server" Target="dd1-ct" Group="group" OverClass="dd-over">
<NotifyDrop Fn="notifyDrop" />
</ext:DropTarget>
<ext:DropTarget ID="DropTarget2" runat="server" Target="dd2-ct" Group="group" OverClass="dd-over">
<NotifyDrop Fn="notifyDrop" />
</ext:DropTarget>
<asp:UpdatePanel ID="evilPanel" runat="server" UpdateMode="Conditional" RenderMode="Block" >
<Triggers>
<asp:AsyncPostBackTrigger ControlID="BigButton" EventName="Click" />
</Triggers>
<ContentTemplate>
<div class="dd-ct" id="dd1-ct">
<div class="dd-item" id="dd1-item1">Item 1.1</div>
<div class="dd-item" id="dd1-item2">Item 1.2</div>
<div class="dd-item" id="dd1-item3">Item 1.3</div>
</div>
<div class="dd-ct" id="dd2-ct">
<div class="dd-item" id="dd2-item1">Item 2.1</div>
<div class="dd-item" id="dd2-item2">Item 2.2</div>
<div class="dd-item" id="dd2-item3">Item 2.3</div>
</div>
<asp:Literal ID="SomeText" runat="server" Text="Some Random Text" />
</div>
</ContentTemplate>
</asp:UpdatePanel>
<asp:Button ID="BigButton" runat="server" Text="Update UpdatePanel" />
</form>
</body>
</html>
Code Behind:using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace CJLRDWeb.Tests
{
public partial class DragProblem : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected override void OnPreRender(EventArgs e)
{
base.OnPreRender(e);
if (IsPostBack)
{
SomeText.Text = "Bob's your uncle";
}
}
}
}
Last edited by Daniil; Oct 28, 2011 at 4:14 PM.
Reason: [CLOSED]