dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 27

Thread: to save the coordinates in database

  1. #1
    Join Date
    Mar 2008
    Posts
    31

    Unhappy to save the coordinates in database

    hai
    i am doing an web application in c#....want to drag and drop the image in to another image and that coordinates should be save inthe database...........plz help..........
    TRUELY
    LAD

  2. #2
    Join Date
    Nov 2002
    Location
    .NET 3.5 VS2008
    Posts
    1,039

    Re: to save the coordinates in database

    Great. Where you having the problem? Have you tried to do it? I assume you know how to save data in the database. Perhaps your problem is how to get the coordinates? Or how to do the drag and drop? With what you have said so far very few people will be willing to help you. If you give more details and if you've tried something yourself more will help you.

  3. #3
    Join Date
    Mar 2008
    Posts
    31

    Re: to save the coordinates in database

    Well....i am able to drag and drop the image.....and ofcourse i know how to save the data in the database...my problem is how to get the coordinates of that moved image....

  4. #4
    Join Date
    Nov 2002
    Location
    .NET 3.5 VS2008
    Posts
    1,039

    Re: to save the coordinates in database

    How are you doing the drag and drop?

  5. #5
    Join Date
    Mar 2008
    Posts
    31

    Re: to save the coordinates in database

    to be clear i have send the code................






    <html>
    <head>
    <style>
    img
    {
    position:relative;
    }
    </style>
    <script type="text/javascript">
    mouseover=true;
    function coordinates()
    {
    if (!moveMe)
    {
    return;
    }
    if (event.srcElement.id=="moveMe")
    {
    mouseover=true;
    pleft=document.getElementById('moveMe').style.pixelLeft;
    ptop=document.getElementById('moveMe').style.pixelTop;
    xcoor=event.clientX;
    ycoor=event.clientY;
    document.onmousemove=moveImage;
    }
    }

    function moveImage()
    {
    if (mouseover&&event.button==1)
    {
    document.getElementById('moveMe').style.pixelLeft=pleft+event.clientX-xcoor;
    document.getElementById('moveMe').style.pixelTop=ptop+event.clientY-ycoor;
    return false;
    }
    }

    function mouseup()
    {
    mouseover=false;
    }
    document.onmousedown=coordinates;
    document.onmouseup=mouseup;
    </script>
    </head>
    <body>
    <img id="moveMe" src="smiley.gif" width="32" height="32"><br />
    <b>Drag and drop the image</b>
    </body>
    </html>

  6. #6
    Join Date
    Nov 2002
    Location
    .NET 3.5 VS2008
    Posts
    1,039

    Re: to save the coordinates in database

    If you add runat="server" to the image you should be able to access it from your C# code easily. You will be able to get the current coordinates and save them to the database. You could have a button and in the handler for the click event you could do all that.

    Did you want to save to the database at the end of the drag and drop without an explicit postback through a button click or something like that? That's possible but it requires a slightly different approach.

  7. #7
    Join Date
    Mar 2008
    Posts
    31

    Re: to save the coordinates in database

    ok......s i wnt to save it by clicking the button.......how i could access in c# to get the coordinates.....plz be more clear.....

  8. #8
    Join Date
    Nov 2002
    Location
    .NET 3.5 VS2008
    Posts
    1,039

    Re: to save the coordinates in database

    Here's a little sample. For it to work you would have to define the top and left style for your image. I've done it inline. I suppose that could be changed. As you can see I've set initial values for the top and left. But after the drag and drop operations those would change so hopefully when you click the "save" button you would get the latest coordinates. Try it out.

    Code:
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>Untitled Page</title>
        <script runat="server">
        private void OnSave(object sender, EventArgs e)
        {
          string top = moveMe.Style["top"];
          string left = moveMe.Style["left"];
          // You can now write the values to the database.
        }
        </script>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
          <img id="moveMe" runat="server" alt="moveMe" src="~/Images/2715.jpg" width="50" height="120" style="position: absolute; top: 100px; left: 200px;"/>
          <asp:Button ID="saveButton" runat="server" Text="Save" OnClick="OnSave"/>
        </div>
        </form>
    </body>
    </html>

  9. #9
    Join Date
    Mar 2008
    Posts
    31

    Unhappy Re: to save the coordinates in database

    hai
    thank u............i got an idea from ur coding....actualy i have send u an drag and drop javascript.....i have done it and its working.....but its working for only one image......how could i done for more than one image.....?

  10. #10
    Join Date
    Nov 2002
    Location
    .NET 3.5 VS2008
    Posts
    1,039

    Re: to save the coordinates in database

    What is the part that is only working for one image: the drag and drop or the saving the coordinates?

    I didn't look to closely at the drag and drop javascript. Could you please edit your post and put the code in code tags? It would be easier to look at it and understand what is happening. But I suspect you have hard-coded the id of the image everywhere.

  11. #11
    Join Date
    Mar 2008
    Posts
    31

    Unhappy Re: to save the coordinates in database

    i am having problem in drag and drop.........


    <html>
    <head>
    <style>
    img
    {
    position:relative;
    }
    </style>
    <script type="text/javascript">
    mouseover=true;
    function coordinates()
    {
    if (!moveMe)
    {
    return;
    }
    if (event.srcElement.id=="moveMe")
    {
    mouseover=true;
    pleft=document.getElementById('moveMe').style.pixelLeft;
    ptop=document.getElementById('moveMe').style.pixelTop;
    xcoor=event.clientX;
    ycoor=event.clientY;
    document.onmousemove=moveImage;
    }
    }

    function moveImage()
    {
    if (mouseover&&event.button==1)
    {
    document.getElementById('moveMe').style.pixelLeft=pleft+event.clientX-xcoor;
    document.getElementById('moveMe').style.pixelTop=ptop+event.clientY-ycoor;
    return false;
    }
    }

    function mouseup()
    {
    mouseover=false;
    }
    document.onmousedown=coordinates;
    document.onmouseup=mouseup;
    </script>
    </head>
    <body>
    <img id="moveMe" src="smiley.gif" width="32" height="32"><br />
    <b>Drag and drop the image</b>
    </body>
    </html>
    Last edited by laddu; April 18th, 2008 at 06:31 AM.

  12. #12
    Join Date
    Nov 2002
    Location
    .NET 3.5 VS2008
    Posts
    1,039

    Re: to save the coordinates in database

    This is what I meant by using code tags and formatting the code. I'm sure you can appreciate the difference...
    Code:
    <html>
    <head>
      <style>
        img
        {
          position:relative;
        }
      </style>
      <script type="text/javascript">
        mouseover=true;
        function coordinates()
        {
          if (!moveMe)
          {
            return;
          }
          if (event.srcElement.id=="moveMe")
          {
            mouseover=true;
            pleft=document.getElementById('moveMe').style.pixelLeft;
            ptop=document.getElementById('moveMe').style.pixelTop;
            xcoor=event.clientX;
            ycoor=event.clientY;
            document.onmousemove=moveImage;
          }
        }
    
        function moveImage()
        {
          if (mouseover&&event.button==1)
          {
            document.getElementById('moveMe').style.pixelLeft=pleft+event.clientX-xcoor;
            document.getElementById('moveMe').style.pixelTop=ptop+event.clientY-ycoor;
            return false;
          }
        }
    
        function mouseup()
        {
          mouseover=false;
        }
    
        document.onmousedown=coordinates;
        document.onmouseup=mouseup;
      </script>
    </head>
    <body>
      <img id="moveMe" src="smiley.gif" width="32" height="32"><br />
      <b>Drag and drop the image</b>
    </body>
    </html>
    I'm sure someone will give you some feedback. I might do so myself if I have time to look at it later.

  13. #13
    Join Date
    Mar 2008
    Posts
    31

    Unhappy Re: to save the coordinates in database

    hai
    thanks......did u see to it?i have tried.....but the image is moving inch by inch....to be more clear



    <style>fgh
    IMG { POSITION: relative }
    </style>
    <script type="text/javascript">
    mouseover=true;
    var Imageflg="false";
    var Imageflg1="false";

    function coordinates()
    {
    //alert("hj");
    //if (!moveMe)
    // {
    // return;
    // }
    if (event.srcElement.id=="moveMe")
    {
    Imageflg="true";
    mouseover=true;

    pleft=document.getElementById('moveMe').style.pixelLeft;
    ptop=document.getElementById('moveMe').style.pixelTop;
    xcoor=event.clientX;
    ycoor=event.clientY;
    document.onmousemove=moveImage;

    }
    if(event.srcElement.id=="moveMe1")
    {
    Imageflg1="true";
    mouseover=true;
    pleft=document.getElementById('moveMe1').style.pixelLeft;
    ptop=document.getElementById('moveMe1').style.pixelTop;
    xcoor=event.clientX;
    ycoor=event.clientY;
    document.onmousemove=moveImage;


    }
    }

    function moveImage()
    {
    if (mouseover&& event.button==1)
    {
    if(Imageflg=="true")
    {
    document.getElementById('moveMe').style.pixelLeft=pleft+event.clientX-xcoor;
    document.getElementById('moveMe').style.pixelTop=ptop+event.clientY-ycoor;
    Imageflg="false";
    Imageflg1="false";
    return false;
    }
    if(Imageflg1=="true" )
    {
    document.getElementById('moveMe1').style.pixelLeft=pleft+event.clientX-xcoor;
    document.getElementById('moveMe1').style.pixelTop=ptop+event.clientY-ycoor;
    Imageflg="false";
    Imageflg1="false";

    return false;
    }
    }
    }

    function mouseup()
    {
    mouseover=false;
    //alert("jklk");
    }
    function Imagef()
    {
    }
    document.onmousedown=coordinates;
    document.onmouseup=mouseup;
    Last edited by laddu; April 22nd, 2008 at 12:57 AM.

  14. #14
    Join Date
    Mar 2008
    Posts
    31

    Re: to save the coordinates in database

    HAI
    i have try to save the coordinates......its saving but.....the default position of top and left.....its not saving the coordinates after that image is moved.................
    help me
    lad

  15. #15
    Join Date
    Nov 2002
    Location
    .NET 3.5 VS2008
    Posts
    1,039

    Re: to save the coordinates in database

    Quote Originally Posted by laddu
    HAI
    i have try to save the coordinates......its saving but.....the default position of top and left.....its not saving the coordinates after that image is moved.................
    help me
    lad
    Show us how you are getting and saving the coordinates. Please use code tags and not "quote" tags.

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)