Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 116147
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T03:07:55+00:00 2026-05-11T03:07:55+00:00

I’m using jQuery UI’s draggable and droppable libraries in a simple ASP.NET proof of

  • 0

I’m using jQuery UI’s draggable and droppable libraries in a simple ASP.NET proof of concept application. This page uses the ASP.NET AJAX UpdatePanel to do partial page updates. The page allows a user to drop an item into a trashcan div, which will invoke a postback that deletes a record from the database, then rebinds the list (and other controls) that the item was drug from. All of these elements (the draggable items and the trashcan div) are inside an ASP.NET UpdatePanel.

Here is the dragging and dropping initialization script:

    function initDragging()     {         $('.person').draggable({helper:'clone'});         $('#trashcan').droppable({             accept: '.person',             tolerance: 'pointer',             hoverClass: 'trashcan-hover',             activeClass: 'trashcan-active',             drop: onTrashCanned         });     }      $(document).ready(function(){         initDragging();          var prm = Sys.WebForms.PageRequestManager.getInstance();         prm.add_endRequest(function()         {             initDragging();         });     });      function onTrashCanned(e,ui)     {         var id = $('input[id$=hidID]', ui.draggable).val();         if (id != undefined)         {             $('#hidTrashcanID').val(id);             __doPostBack('btnTrashcan','');         }      } 

When the page posts back, partially updating the UpdatePanel’s content, I rebind the draggables and droppables. When I then grab a draggable with my cursor, I get an ‘htmlfile: Unspecified error.’ exception. I can resolve this problem in the jQuery library by replacing elem.offsetParent with calls to this function that I wrote:

function IESafeOffsetParent(elem) {     try     {         return elem.offsetParent;     }     catch(e)     {                 return document.body;     } } 

I also have to avoid calls to elem.getBoundingClientRect() as it throws the same error. For those interested, I only had to make these changes in the jQuery.fn.offset function in the Dimensions Plugin.

My questions are:

  • Although this works, are there better ways (cleaner; better performance; without having to modify the jQuery library) to solve this problem?
  • If not, what’s the best way to manage keeping my changes in sync when I update the jQuery libraries in the future? For, example can I extend the library somewhere other than just inline in the files that I download from the jQuery website.

Update:

@some It’s not publicly accessible, but I will see if SO will let me post the relevant code into this answer. Just create an ASP.NET Web Application (name it DragAndDrop) and create these files. Don’t forget to set Complex.aspx as your start page. You’ll also need to download the jQuery UI drag and drop plug in as well as jQuery core

Complex.aspx

<%@ Page Language='C#' AutoEventWireup='true' CodeBehind='Complex.aspx.cs' Inherits='DragAndDrop.Complex' %>  <!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>Untitled Page</title>     <script src='jquery-1.2.6.min.js' type='text/javascript'></script>     <script src='jquery-ui-personalized-1.5.3.min.js' type='text/javascript'></script>     <script type='text/javascript'>         function initDragging()         {             $('.person').draggable({helper:'clone'});             $('#trashcan').droppable({                 accept: '.person',                 tolerance: 'pointer',                 hoverClass: 'trashcan-hover',                 activeClass: 'trashcan-active',                 drop: onTrashCanned             });         }          $(document).ready(function(){             initDragging();              var prm = Sys.WebForms.PageRequestManager.getInstance();             prm.add_endRequest(function()             {                 initDragging();             });         });          function onTrashCanned(e,ui)         {             var id = $('input[id$=hidID]', ui.draggable).val();             if (id != undefined)             {                 $('#hidTrashcanID').val(id);                 __doPostBack('btnTrashcan','');             }          }     </script> </head> <body>     <form id='form1' runat='server'>     <asp:ScriptManager ID='ScriptManager1' runat='server'>     </asp:ScriptManager>     <div>         <asp:UpdatePanel ID='updContent' runat='server' UpdateMode='Always'>     <ContentTemplate>         <asp:LinkButton ID='btnTrashcan' Text='trashcan' runat='server' CommandName='trashcan'              onclick='btnTrashcan_Click' style='display:none;'></asp:LinkButton>         <input type='hidden' id='hidTrashcanID' runat='server' />         <asp:Button ID='Button1' runat='server' Text='Save' onclick='Button1_Click' />         <table>             <tr>                 <td style='width: 300px;'>                     <asp:DataList ID='lstAllPeople' runat='server' DataSourceID='odsAllPeople'                         DataKeyField='ID'>                         <ItemTemplate>                             <div class='person'>                                 <asp:HiddenField ID='hidID' runat='server' Value='<%# Eval('ID') %>' />                                 Name:                                 <asp:Label ID='lblName' runat='server' Text='<%# Eval('Name') %>' />                                 <br />                                 <br />                             </div>                         </ItemTemplate>                     </asp:DataList>                     <asp:ObjectDataSource ID='odsAllPeople' runat='server' SelectMethod='SelectAllPeople'                          TypeName='DragAndDrop.Complex+DataAccess'                          onselecting='odsAllPeople_Selecting'>                         <SelectParameters>                             <asp:Parameter Name='filter' Type='Object' />                         </SelectParameters>                     </asp:ObjectDataSource>                 </td>                 <td style='width: 300px;vertical-align:top;'>                     <div id='trashcan'>                         drop here to delete                     </div>                     <asp:DataList ID='lstPeopleToDelete' runat='server'                          DataSourceID='odsPeopleToDelete'>                         <ItemTemplate>                             ID:                             <asp:Label ID='IDLabel' runat='server' Text='<%# Eval('ID') %>' />                             <br />                             Name:                             <asp:Label ID='NameLabel' runat='server' Text='<%# Eval('Name') %>' />                             <br />                             <br />                         </ItemTemplate>                     </asp:DataList>                     <asp:ObjectDataSource ID='odsPeopleToDelete' runat='server'                          onselecting='odsPeopleToDelete_Selecting' SelectMethod='GetDeleteList'                          TypeName='DragAndDrop.Complex+DataAccess'>                         <SelectParameters>                             <asp:Parameter Name='list' Type='Object' />                         </SelectParameters>                     </asp:ObjectDataSource>                 </td>             </tr>         </table>         </ContentTemplate>     </asp:UpdatePanel>     </div>     </form> </body> </html> 

Complex.aspx.cs

namespace DragAndDrop {     public partial class Complex : System.Web.UI.Page     {         protected void Page_Load(object sender, EventArgs e)         {         }          protected List<int> DeleteList         {             get             {                 if (ViewState['dl'] == null)                 {                     List<int> dl = new List<int>();                     ViewState['dl'] = dl;                      return dl;                 }                 else                 {                     return (List<int>)ViewState['dl'];                 }             }         }          public class DataAccess         {             public IEnumerable<Person> SelectAllPeople(IEnumerable<int> filter)             {                 return Database.SelectAll().Where(p => !filter.Contains(p.ID));             }              public IEnumerable<Person> GetDeleteList(IEnumerable<int> list)             {                 return Database.SelectAll().Where(p => list.Contains(p.ID));             }         }          protected void odsAllPeople_Selecting(object sender, ObjectDataSourceSelectingEventArgs e)         {             e.InputParameters['filter'] = this.DeleteList;         }          protected void odsPeopleToDelete_Selecting(object sender, ObjectDataSourceSelectingEventArgs e)         {             e.InputParameters['list'] = this.DeleteList;         }          protected void Button1_Click(object sender, EventArgs e)         {             foreach (int id in DeleteList)             {                 Database.DeletePerson(id);             }              DeleteList.Clear();             lstAllPeople.DataBind();             lstPeopleToDelete.DataBind();         }          protected void btnTrashcan_Click(object sender, EventArgs e)         {             int id = int.Parse(hidTrashcanID.Value);             DeleteList.Add(id);             lstAllPeople.DataBind();             lstPeopleToDelete.DataBind();         }     } } 

Database.cs

namespace DragAndDrop {     public static class Database     {         private static Dictionary<int, Person> _people = new Dictionary<int,Person>();         static Database()         {             Person[] people = new Person[]             {                 new Person('Chad')                 , new Person('Carrie')                 , new Person('Richard')                 , new Person('Ron')             };             foreach (Person p in people)             {                 _people.Add(p.ID, p);             }         }          public static IEnumerable<Person> SelectAll()         {             return _people.Values;         }          public static void DeletePerson(int id)         {             if (_people.ContainsKey(id))             {                 _people.Remove(id);             }         }          public static Person CreatePerson(string name)         {             Person p = new Person(name);             _people.Add(p.ID, p);              return p;         }     }      public class Person     {         private static int _curID = 1;         public int ID { get; set; }         public string Name { get; set; }         public Person()         {             ID = _curID++;         }          public Person(string name)             : this()         {             Name = name;         }     } } 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T03:07:56+00:00Added an answer on May 11, 2026 at 3:07 am

    @arilanto – I include this script after my jquery scripts. Performance wise, it’s not the best solution, but it is a quick easy work around.

    function IESafeOffsetParent(elem) {     try     {        return elem.offsetParent;     }     catch(e)     {               return document.body;     } }  // The Offset Method // Originally By Brandon Aaron, part of the Dimension Plugin // http://jquery.com/plugins/project/dimensions jQuery.fn.offset = function() { /// <summary> ///     Gets the current offset of the first matched element relative to the viewport. /// </summary> /// <returns type='Object'>An object with two Integer properties, 'top' and 'left'.</returns>  var left = 0, top = 0, elem = this[0], results;  if ( elem ) with ( jQuery.browser ) {     var parent     = elem.parentNode,         offsetChild  = elem,         offsetParent = IESafeOffsetParent(elem),         doc       = elem.ownerDocument,         safari2   = safari && parseInt(version) < 522 && !/adobeair/i.test(userAgent),         css       = jQuery.curCSS,         fixed       = css(elem, 'position') == 'fixed';      // Use getBoundingClientRect if available     if (false && elem.getBoundingClientRect) {         var box = elem.getBoundingClientRect();          // Add the document scroll offsets         add(box.left + Math.max(doc.documentElement.scrollLeft, doc.body.scrollLeft),             box.top  + Math.max(doc.documentElement.scrollTop,  doc.body.scrollTop));          // IE adds the HTML element's border, by default it is medium which is 2px         // IE 6 and 7 quirks mode the border width is overwritable by the following css html { border: 0; }         // IE 7 standards mode, the border is always 2px         // This border/offset is typically represented by the clientLeft and clientTop properties         // However, in IE6 and 7 quirks mode the clientLeft and clientTop properties are not updated when overwriting it via CSS         // Therefore this method will be off by 2px in IE while in quirksmode         add( -doc.documentElement.clientLeft, -doc.documentElement.clientTop );      // Otherwise loop through the offsetParents and parentNodes     } else {          // Initial element offsets         add( elem.offsetLeft, elem.offsetTop );          // Get parent offsets         while ( offsetParent ) {             // Add offsetParent offsets             add( offsetParent.offsetLeft, offsetParent.offsetTop );              // Mozilla and Safari > 2 does not include the border on offset parents             // However Mozilla adds the border for table or table cells             if ( mozilla && !/^t(able|d|h)$/i.test(offsetParent.tagName) || safari && !safari2 )                 border( offsetParent );              // Add the document scroll offsets if position is fixed on any offsetParent             if ( !fixed && css(offsetParent, 'position') == 'fixed' )                 fixed = true;              // Set offsetChild to previous offsetParent unless it is the body element             offsetChild  = /^body$/i.test(offsetParent.tagName) ? offsetChild : offsetParent;             // Get next offsetParent             offsetParent = offsetParent.offsetParent;         }          // Get parent scroll offsets         while ( parent && parent.tagName && !/^body|html$/i.test(parent.tagName) ) {             // Remove parent scroll UNLESS that parent is inline or a table to work around Opera inline/table scrollLeft/Top bug             if ( !/^inline|table.*$/i.test(css(parent, 'display')) )                 // Subtract parent scroll offsets                 add( -parent.scrollLeft, -parent.scrollTop );              // Mozilla does not add the border for a parent that has overflow != visible             if ( mozilla && css(parent, 'overflow') != 'visible' )                 border( parent );              // Get next parent             parent = parent.parentNode;         }          // Safari <= 2 doubles body offsets with a fixed position element/offsetParent or absolutely positioned offsetChild         // Mozilla doubles body offsets with a non-absolutely positioned offsetChild         if ( (safari2 && (fixed || css(offsetChild, 'position') == 'absolute')) ||             (mozilla && css(offsetChild, 'position') != 'absolute') )                 add( -doc.body.offsetLeft, -doc.body.offsetTop );          // Add the document scroll offsets if position is fixed         if ( fixed )             add(Math.max(doc.documentElement.scrollLeft, doc.body.scrollLeft),                 Math.max(doc.documentElement.scrollTop,  doc.body.scrollTop));     }      // Return an object with top and left properties     results = { top: top, left: left }; }  function border(elem) {     /// <summary>     ///     This method is internal.     /// </summary>     /// <private />     add( jQuery.curCSS(elem, 'borderLeftWidth', true), jQuery.curCSS(elem, 'borderTopWidth', true) ); }  function add(l, t) {     /// <summary>     ///     This method is internal.     /// </summary>     /// <private />     left += parseInt(l, 10) || 0;     top += parseInt(t, 10) || 0; }  return results; }; 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 161k
  • Answers 161k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Sorry I don't have time to do this question justice,… May 12, 2026 at 11:46 am
  • Editorial Team
    Editorial Team added an answer I am not familiar with the stuff you are using… May 12, 2026 at 11:46 am
  • Editorial Team
    Editorial Team added an answer You can convert between the coordinate spaces of different elements… May 12, 2026 at 11:46 am

Related Questions

I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I am currently running into a problem where an element is coming back from
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.