Modal popup jumps on drag after setting position (before showing)

Last post 11-07-2009 8:06 AM by cjduva. 5 replies.

Sort Posts:

  • Modal popup jumps on drag after setting position (before showing)

    01-31-2008, 9:32 PM
    • Member
      1 point Member
    • cfairles
    • Member since 02-01-2008, 2:00 AM
    • Posts 3

    The layout is header, side menu, content area. Side menu constant width, content area resizes with browser.

    Virtual Earth page fills the content area. I add a mouse click event and set the X,Y of the modal popup to the x,y where the user clicked in the map. The modal popup appears exactly where it should, but if you click on the "drag" label, it jumps to the right and down. My guess is because its within the master_content div which has position:absolute.

    I've stepped through the code, so here's an example of the symtom. In the startDragDrop, mousePosition is (717, 286). Then the drag visual is FORCED to absolute positioning (I don't know why it backs up originalPosition). The startingPoint is set to the mousePosition, (717, 286). scrollOffset is 0, but because abolute positioning was forced, this gets executed:

    dragVisual.startingPoint = this.subtractPoints(dragVisual.startingPoint, $common.getLocation(dragVisual));

    Now startingPoint is (49, 25). I step into the drag function where it subtracts the startingPoint from the mousePosition, leaving position = (668, 261). Then it sets the position ala:

    $common.setLocation(this._activeDragVisual, position);

    And the modal popup jumps.

     

    Pasted below is the relevant sections of my code. You'll notive an empty <div style="position:fixed;top:0px;left:0px"></div>. If you wrap the popup panel with this div, then the jump on drag doesn't occur, but the popup doesn't appear in the right position on right click! There's probably ways of getting around it by tracking positions manually, but I'm fairly new to asp.net/ajax/javascript/web dev in general so I prefer simple solutions. Any help is much appreciated.

     

    MasterPage.master (relevant portions):

    <body id="MasterBody">

    <form id="MasterForm" runat="server">

    <asp:ScriptManager runat="server" ID="MasterScriptManager" />

    <div id="master_body">

    <div id="master_header">

    </div>

    <div id="master_menu">

    </div>

    <div id="master_content">

    <asp:ContentPlaceHolder id="phContent" runat="server" />

    </div>

    </div>

    </form>

    </body>

    VirtualEarth.aspx.cs

    protected void Page_Load(object sender, EventArgs e)

    {

    ScriptManager sm = (ScriptManager)Master.FindControl("MasterScriptManager");ScriptReference sf = new ScriptReference("http://dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=6");

    sm.Scripts.Add(sf);

    }

     

    VirtualEarth.aspx

    <asp:Content ID="Content3" ContentPlaceHolderID="phContent" Runat="Server">

    <div id="map" style="position:absolute;width:100%;height:100%;"></div>

    <script type="text/javascript">

    var map = null;
    var defaultLatLong = null;

     

    function showPopup(event)

    {

    if(event.rightMouseButton)

    {

    var x = event.mapX;

    var y = event.mapY;

     

    var pixel = new VEPixel(x, y);

    var latlong = map.PixelToLatLong(pixel);

    var popupLabel = $get('PopupLabel');

    popupLabel.innerText =

    "(" + latlong.Latitude.toFixed(3) + ", " + latlong.Longitude.toFixed(3) + ")";

     

    var popupBehavior = $find('PopupBehavior');

    popupBehavior.set_X(event.mapX);

    popupBehavior.set_Y(event.mapY);

    popupBehavior.show();

    }

    }

     

    function hidePopup(event)

    {

    var popupBehavior = $find('PopupBehavior');

    popupBehavior.hide();

    }

     

    function LoadMap()

    {

    defaultLatLong =
    new VELatLong(43.4639, -80.5222);map = new VEMap('map');

    map.LoadMap(defaultLatLong, 10, VEMapStyle.Road);

     

    // The onclick event to call the callPopUp function

    map.AttachEvent("onclick", showPopup);

    }

     

    Sys.Application.add_load(LoadMap);

    </script>

     

    <asp:Panel ID="PopupPanel" runat="server" CssClass="popup" style="display:none;">

    <asp:Panel ID="PopupDragHandle" runat="server" Style="cursor:move;">

    ModalPopup (click me to drag)</asp:Panel>

    <span id="PopupLabel" style="text-align:center;"></span>

    <hr />

    <asp:Button ID="OkButton" runat="server" Text="Ok" />

    </asp:Panel>

    <asp:Button runat="server" ID="hiddenControlForPopup" style="display:none"/>

    <act:ModalPopupExtender ID="Popup" runat="server" OkControlID="OkButton"

    TargetControlID="hiddenControlForPopup" BehaviorID="PopupBehavior"

    PopupControlID="PopupPanel" BackgroundCssClass="popup_background"

    PopupDragHandleControlID="PopupDragHandle" RepositionMode="None">

    </act:ModalPopupExtender>

    <div style="position: fixed; top:0px; left:0px;">

    </div>

    <script type="text/javascript">

    // The following snippet works around a problem where FloatingBehavior

    // doesn't allow drops outside the "content area" of the page - where "content

    // area" is a little unusual for our sample web pages due to their use of CSS

    // for layout.

    function setBodyHeightToContentHeight() {document.body.style.height = Math.max(document.documentElement.scrollHeight, document.body.scrollHeight) + "px";

    }

    setBodyHeightToContentHeight();

    $addHandler(window,
    "resize", setBodyHeightToContentHeight);

    </script>

    </asp:Content>

    StyleSheet.css 

     

    * { margin: 0; padding: 0; border: none; }

    html { overflow: hidden; }

    body

    {

    overflow: hidden;

    width: 100%;

    height: 100%;

    background-color: #EEEEEE;

    }

    /* Master Page Layout */

    #master_body

    {

    }

    #master_header

    {

    border: solid 1px;

    position: absolute;

    top: 0px;

    left: 0px;

    width: 100%;

    height: 80px;

    overflow: hidden;

    }

    #master_menu

    {

    border: solid 1px;

    position: absolute;

    top: 100px;

    left: 20px;

    bottom: 20px;

    width: 200px;

    overflow: auto;

    }

    #master_content

    {

    border: solid 1px;

    position: absolute;

    top: 100px;

    left: 240px;

    right: 20px;

    bottom: 20px;

    overflow: auto;

    color: #666666;

    }

    .menu_header

    {

    width: 100%;

    height: 25px;

    background-color: #F5F5F5;

    font-weight: bold;

    }

    .menu_content

    {

    background-color: #E8E8E8;

    }

    /*Modal Popup*/

    .popup_background {

    background-color:Gray;

    filter:alpha(opacity=50);

    opacity:0.5;

    }

    .popup

    {

    background-color: #ffffdd;

    border-width: 3px;

    border-style: solid;

    border-color: Gray;

    padding: 3px;

    width: 250px;

    }

     

  • Re: Modal popup jumps on drag after setting position (before showing)

    02-05-2008, 6:28 PM
    Answer
    • Member
      1 point Member
    • cfairles
    • Member since 02-01-2008, 2:00 AM
    • Posts 3
    Solved by editing DragDropScripts.js, line 268:
           //if (dragVisual.style.position == "absolute") {
            //    dragVisual.startingPoint = this.subtractPoints(dragVisual.startingPoint, $common.getLocation(dragVisual));
            //}
            //else {
                var left = parseInt(dragVisual.style.left);
                var top = parseInt(dragVisual.style.top);
                if (isNaN(left)) left = "0";
                if (isNaN(top)) top = "0";
                
                dragVisual.startingPoint = this.subtractPoints(dragVisual.startingPoint, { x: left, y: top });
            //}

    The modal popup no longer jumps on mousedown of the PopupDragHandleControlId element.

     

    Works in IE 7.0.5730.13 and FireFox 2.0.0.11 

  • Re: Modal popup jumps on drag after setting position (before showing)

    12-09-2008, 9:56 AM
    • Member
      39 point Member
    • cjduva
    • Member since 03-06-2005, 10:32 AM
    • Wilmington, NC
    • Posts 72

    Thank you.  Thank you.  Thank you.  Thank you!

    I can't believe that Microsoft has allowed this bug to live for so long.  Now, if they would only fix the bug requiring the setBodyHeightToContentHeight() hack.

    DragPanelExtender is such a useful UI element, and it was really aggravating me that I couldn't get it to work.

    Have you looked at the DropDownShadow code?  It suffers from the same malady. 

    It definitely seems that the AJAX gang and the Master Pages gang need to have a little rumble and settle a few things face to face.

    Thanks again!

    Chris Duva
  • Re: Modal popup jumps on drag after setting position (before showing)

    07-23-2009, 4:25 PM
    • Member
      2 point Member
    • odemus
    • Member since 07-23-2009, 8:24 PM
    • Posts 1

    After editing the js file, did you have to re-compile the toolkit? If not, where did you find the js file to edit?


    Thanks.

  • Re: Modal popup jumps on drag after setting position (before showing)

    11-06-2009, 1:10 PM
    • Member
      266 point Member
    • wabs27
    • Member since 05-31-2005, 4:06 AM
    • New York
    • Posts 106

    How did you recompile the toolit?  When I build it I don't think it builds it properly since Visual Studio stopped recognizing it and give me green squiggly lines on the Ajax Control Toolkit.


    Thanks.

  • Re: Modal popup jumps on drag after setting position (before showing)

    11-07-2009, 8:06 AM
    • Member
      39 point Member
    • cjduva
    • Member since 03-06-2005, 10:32 AM
    • Wilmington, NC
    • Posts 72

    The DragDrop script for the DragPanel extender is named DragDropScripts.js and is located in the Compat\DragDrop folder of the AjaxCcontrolToolkit project.  DragDropScripts.js has been minified.  Click the "Show All Files" button and you will see DragDropScripts.debug.js in the same folder.  You will now be able to find the code referenced on line 268.  I edited this file.

    I ended up opening DragDropScripts.js in my text editor and replacing its contents with the contents of the modified DragDropScripts.debug.js, as I tried renaming the files in the project and it didn't work.  I decided not to worry about the 14KB difference.

    Build the AjaxControlToolkit project (you don't need to build the entire solution).  Remove the reference to the AjaxControlToolkit from your project, and then add it back, selecting the newly built AjaxControlToolkit.DLL.  Check the Bin folder of your project to be sure that it holds the new DLL.  My DLL, in Debug version, ended up at 1,644 KB.  The MS binary-only version is 3,612.

    Chris Duva
Page 1 of 1 (6 items)