How can I get current position of RadWindow in OnClientDragEnd

7 posts, 0 answers
  1. Rabbi
    Rabbi avatar
    4 posts
    Member since:
    Sep 2008

    Posted 16 Nov 2011 Link to this post

     function OnClientDragEnd(sender,args) {
                    var oWd = $find("RadWindow1");
                    var newLocation = oWd.getWindowBounds();             
                }

     <cc:RadWindow runat="server" ID="RadWindow1" Height="300px" Width="400px"
                            NavigateUrl="http://yahoo.com" VisibleOnPageLoad="true" OnClientDragEnd="OnClientDragEnd" />

    in this, getWindowBounds can't get new positon on fly. 
    Please help me.
  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 16 Nov 2011 Link to this post

    Hello,

    Try the following javascript.
    JS:
    function OnClientDragEnd(sender, args)
    {
      var position = sender.getWindowBounds();
      var x = position.x;
      var y= position.y;
      var ht = position.height;
      var w = position.width;
    }        

    Thanks,
    Princy.
  3. Rabbi
    Rabbi avatar
    4 posts
    Member since:
    Sep 2008

    Posted 16 Nov 2011 Link to this post

    thank Princy very much.

    In this case, using  position = sender.getWindowBounds();  only get old postion of radwindows.

    How to get current postion of radwindow during drag it?
  4. Rumen
    Admin
    Rumen avatar
    13747 posts

    Posted 16 Nov 2011 Link to this post

    Hi Rabbi,

    The following code works for me:

    <telerik:RadWindow ID="RadWindow1" VisibleOnPageLoad="true" Width="400" Height="400"
        OnClientDragStart="OnClientDragStart" OnClientDragEnd="OnClientDragEnd" runat="server" NavigateUrl="http://www.telerik.com"></telerik:RadWindow>
        <span id="showCoordinates"></span>
    <script type="text/javascript">
        function OnClientDragStart(sender, args) {
            var position = sender.getWindowBounds();
            var x = position.x;
            var y = position.y;
            $get("showCoordinates").innerHTML = "Coordinates before drag: x:" + x + " y: " + y;
        }
     
        function OnClientDragEnd(sender, args) {
                var position = sender.getWindowBounds();
                var x = position.x;
                var y = position.y;
                $get("showCoordinates").innerHTML = "Coordinates after drag: x:" + x + " y: " + y;
        
    </script>

    The SPAN tag is updated with the new x and y coordinates of the dialog after the drag execution.

    All the best,
    Rumen
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
  5. Rabbi
    Rabbi avatar
    4 posts
    Member since:
    Sep 2008

    Posted 17 Nov 2011 Link to this post

    hi Rumen,

    your code win get old postion of radwindow.  I want to get current of radwindow in DRAG event 

    Please help me.
  6. Marin Bratanov
    Admin
    Marin Bratanov avatar
    4526 posts

    Posted 18 Nov 2011 Link to this post

    Hi Rabbi,

    Your initial question was for the coordinates in the OnClientDragEnd event and the code provided by my colleagues achieves this functionality. 

    You can use the getBounds() method of the static client library we provide and an interval to get the current position while dragging:

    <telerik:RadWindow ID="RadWindow1" VisibleOnPageLoad="true" Width="400" Height="400"
        OnClientDragStart="OnClientDragStart"  OnClientDragEnd="OnClientDragEnd" runat="server"
        NavigateUrl="http://www.telerik.com">
    </telerik:RadWindow>
    <span id="showCoordinates"></span>
    <br />
    <span id="currCoords"></span>
    <script type="text/javascript">
        var timer = null;
        function OnClientDragStart(sender, args)
        {
            var position = sender.getWindowBounds();
            var x = position.x;
            var y = position.y;
            $get("showCoordinates").innerHTML = "Coordinates before drag: x:" + x + " y: " + y;
     
            var popupElem = sender.get_popupElement();
            timer = setInterval(function ()
            {
                var position = $telerik.getBounds(popupElem);
                var x = position.x;
                var y = position.y;
                $get("currCoords").innerHTML = "Current coordinates: x:" + x + " y: " + y;
            }, 10);
        }
     
     
        function OnClientDragEnd(sender, args)
        {
            clearInterval(timer);
            var position = sender.getWindowBounds();
            var x = position.x;
            var y = position.y;
            $get("showCoordinates").innerHTML = "Coordinates after drag: x:" + x + " y: " + y;
        }  
    </script>

    I am also attaching a simple page that shows this in action to this thread.

    All the best,
    Marin
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
  7. Rabbi
    Rabbi avatar
    4 posts
    Member since:
    Sep 2008

    Posted 23 Nov 2011 Link to this post

    Dear Marin,

    Your code is great for me.

    Thank you very much!

Back to Top