I am using the Drag and Drop framework for ASP.NET, and the javascript functionality is working fine. I dynamically create DIV elements which nest inside a parent DIV element, and I assign the drag drop functionality to each of the dynamic divs.
The first set of divs I create are employees:
For Each drRow As DataRow In dsData.Tables(0).Rows strInsert = "<div id='Carer" & drRow.Item("UserId") & "' runat='server' class='Item' style='float: left; margin: 5px 5px 5px 5px; padding: 5px 5px 5px 5px; border: solid 1px black;'>" strInsert = strInsert & drRow.Item("UserName") strInsert = strInsert & "</div>" divCarer.InnerHtml = divCarer.InnerHtml & strInsert Next
For Each drRow As DataRow In dsData.Tables(0).Rows
strInsert = "<div id='Carer" & drRow.Item("UserId") & "' runat='server' class='Item' style='float: left; margin: 5px 5px 5px 5px; padding: 5px 5px 5px 5px; border: solid 1px black;'>"
strInsert = strInsert & drRow.Item("UserName")
strInsert = strInsert & "</div>"
divCarer.InnerHtml = divCarer.InnerHtml & strInsert
Next
Then I create a list of jobs to be assigned to them using the same sort of code.
When I click and drag a Job, the location is correct and the click picks up the correct job and drags it.
However, when I try to drop the item onto the Employee DIVs, the location I can drop them is offset to the right by around 100px from where the DIV appears to be. This is occuring in IE9, Firefox 12 and Chrome v27 (both are fully up to date).
I have tried removing the float, the margins, padding and borders, each time I end up with this 100px offset for the DIV.
Has anyone come across this before? Am I making horrible CSS mistakes or is this something else in the Javascript I'm not aware of?
Here is the section of HTML output (sorry about the mess):
<table width="1000px" style="clear: both"> <tr> <td> <div id="MainContent"> <script type="text/javascript"> Sys.Application.add_load(app_loaded);
function app_loaded() { var dd = new $IG.DragDropBehavior(); var Unresourced = $get("ctl00_ContentPlaceHolder_divUnresourced");
for (var i = 0; i < Unresourced.childNodes.length; i++) { if (Unresourced.childNodes[i].getAttribute) { dd.addSourceElement(Unresourced.childNodes[i]); } }
var Carer = $get("ctl00_ContentPlaceHolder_divCarer");
for (var i = 0; i < Carer.childNodes.length; i++) { if (Carer.childNodes[i].getAttribute) { dd.addTargetElement(Carer.childNodes[i], true); } }
//dd.addTargetElement($get("ctl00_ContentPlaceHolder_divCarer"), true);
dd.get_events().addDropHandler(drop); }
function drop(source, eventArgs) { var Unresourced = $get("ctl00_ContentPlaceHolder_divUnresourced"); //var Error = $get("ctl00_ContentPlaceHolder_lblError"); //var Carer = $get("ctl00_ContentPlaceHolder_divCarer");
//Error.value = '';
//var div = document.createElement("div"); var sourceX = eventArgs.get_manager().get_source().element; var targetX = eventArgs.get_manager().get_targetElement(); var checksentVal = check_sent(sourceX.id, targetX.id);
if (checksentVal == true) { Unresourced.removeChild($get(sourceX.id)); } else { Error.value = 'Not Sent'; }
//div.innerHTML = source.innerHTML; //div.setAttribute("id", source.attributes["id"].value); //div.setAttribute("class", source.attributes["class"].value); //div.setAttribute("className", source.attributes["class"].value); //var dd = new $IG.DragDropBehavior(); //dd.removeSource(div); //Carer.appendChild(div); }
function check_sent(SourceId, TargetId) { var TextboxSource = $get("ctl00_ContentPlaceHolder_txtCarerEvent"); var TextboxTarget = $get("ctl00_ContentPlaceHolder_txtCarerId"); //var Button = $get("inputCarer");
//var Button = document.getElementById("ctl00_ContentPlaceHolder_btnCarerClick"); //if (typeof Button.onclick == "function") { // Button.onclick.apply(Button); //}
TextboxSource.value = SourceId; TextboxTarget.value = TargetId;
var btn = document.getElementById("ctl00_ContentPlaceHolder_btnCarerClick"); if (btn) btn.click();
//Button.click;
//if (Textbox.value == "1") { // return true; //} //else { // return false; //} } </script> <div> <span id="ctl00_ContentPlaceHolder_lblError" class="Item" style="color:Red;"></span> <input name="ctl00$ContentPlaceHolder$txtCarerEvent" type="text" id="ctl00_ContentPlaceHolder_txtCarerEvent" class="hiddenItem" /> <input name="ctl00$ContentPlaceHolder$txtCarerId" type="text" id="ctl00_ContentPlaceHolder_txtCarerId" class="hiddenItem" /> <input type="submit" name="ctl00$ContentPlaceHolder$btnCarerClick" value="" id="ctl00_ContentPlaceHolder_btnCarerClick" class="hiddenItem" /> </div> <div style="clear: both;"></div> <div id="ctl00_ContentPlaceHolder_divCarer" style="width: 100%; float: right;"><div id='Carer526' runat='server' class='Item' style='float: left; margin: 5px 5px 5px 5px; padding: 5px 5px 5px 5px; border: solid 1px black;'>Martha Carer</div><div id='Carer527' runat='server' class='Item' style='float: left; margin: 5px 5px 5px 5px; padding: 5px 5px 5px 5px; border: solid 1px black;'>Bob Marley</div><div id='Carer528' runat='server' class='Item' style='float: left; margin: 5px 5px 5px 5px; padding: 5px 5px 5px 5px; border: solid 1px black;'>Ian Slaughter</div><div id='Carer529' runat='server' class='Item' style='float: left; margin: 5px 5px 5px 5px; padding: 5px 5px 5px 5px; border: solid 1px black;'>John Smith</div><div id='Carer530' runat='server' class='Item' style='float: left; margin: 5px 5px 5px 5px; padding: 5px 5px 5px 5px; border: solid 1px black;'>Ian Jones</div></div> <div style="clear: both;"></div> <div id="ctl00_ContentPlaceHolder_divUnresourced" style="width: 100%; float: left;"><div style='clear: both;'></div><div id='Job8001779' runat='server' class='Item moveable' style='float: left; margin: 5px 5px 5px 5px; padding: 5px 5px 5px 5px; border: solid 1px black;'>19:00 : will smith</div></div> <div style="clear: both;"></div>
</div> </td> </tr> </table>
Hi Ben,
I tried to copy/paste those codes in a sample, but format is messed and content is not sufficient for testing.
I think, that shifts which you describe, come from configuration of html and layout of its elements.You may build a simple sample (aspx/aspx.cs/vb files are enough) which can be used to run that sample, zip it and attach within Options tab.
Hi Viktor,
Thanks for your response.
I created a new page with no outside influences of other Javascripts or CSS in order to show you, and the drag drop worked perfectly, so it must be something else within our site causing the issues.
I'm going to have to go through and slowly rip everything out to work out what is causing the issues. But at least I know it is not caused by the drag/drop itself.
Regards,
Ben
You may use F12 (developer tools) or browser (better IE9/10). Select/point to element with wrong location and experiment with current css attributes applied to that element (and maybe its parent): enable/disable/modify attributes and watch instant effect of those changes. It will allow you to exactly identify "bad" attribute, in which css class it is defined and where that class in located.
Unfortunately this does not seem to be a CSS based problem, as I have stripped all the CSS out of the site and it is still occuring.
When I remove the MasterPage from the site the page in question works as intended, but I have not yet managed to find any item in a Masterpage which causes the problem.
I have taken the new project version which I created to show you and am slowly adding each item from our existing MasterPage to try and find out what might be the cause of the problem.