Results 1 to 17 of 17

Thread: [RESOLVED] Button click and hold

  1. #1

    Thread Starter
    New Member daarsk's Avatar
    Join Date
    Jun 2014
    Location
    Melbourne, Australia
    Posts
    13

    Resolved [RESOLVED] Button click and hold

    I have an asp Button1 increasing Label1 by value 1 on each click (VB), how would I get the label to increase by holding the button instead of click click click.

    Thanks James

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,344

    Re: Button click and hold

    So, the application is ASP.NET Web Forms?

  3. #3

    Thread Starter
    New Member daarsk's Avatar
    Join Date
    Jun 2014
    Location
    Melbourne, Australia
    Posts
    13

    Re: Button click and hold

    Yes it is. ASPX with VB code behind

  4. #4
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: Button click and hold

    Thread moved to the ASP.Net forum.

  5. #5
    Frenzied Member KGComputers's Avatar
    Join Date
    Dec 2005
    Location
    Cebu, PH
    Posts
    2,020

    Re: Button click and hold

    You can't achieve that using .vb/server side code, only in javascript/jquery.
    See link: Javascript-easily-do-a-continuous-action-on-mouse-hold
    CodeBank: VB.NET & C#.NET | ASP.NET
    Programming: C# | VB.NET
    Blogs: Personal | Programming
    Projects: GitHub | jsFiddle
    ___________________________________________________________________________________

    Rating someone's post is a way of saying Thanks...

  6. #6
    King of sapila
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    6,605

    Re: Button click and hold

    Theoretically it may be done with an updatepanel and a timer but it would still need Javascript for the mouse down.
    That is why Javascript rulez and server side (MVC) sucks!!! :P
    Have a nice weekend.
    ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
    πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·

  7. #7

    Thread Starter
    New Member daarsk's Avatar
    Join Date
    Jun 2014
    Location
    Melbourne, Australia
    Posts
    13

    Re: Button click and hold

    Thanks for moving thread (sorry)

    I'm afraid my knowledge of Java sits somewhere between 0 and null. I guess I put the code between <script type="text/javascript"> tags on my aspx page? Then how do tie that code to a button? In fact I have 2 buttons; 1 to go up and 1 to go down.

    It may take a bit for me to get my head around this, sorry if I'm too much trouble. Help is obviously highly appreciated.

    Thanks James

  8. #8

    Thread Starter
    New Member daarsk's Avatar
    Join Date
    Jun 2014
    Location
    Melbourne, Australia
    Posts
    13

    Re: Button click and hold

    I also found this, but I can't get it to work.
    http://stackoverflow.com/questions/1...n-hold-support

  9. #9
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,344

    Re: Button click and hold

    Quote Originally Posted by sapator View Post
    Theoretically it may be done with an updatepanel and a timer but it would still need Javascript for the mouse down.
    That is why Javascript rulez and server side (MVC) sucks!!! :P
    Have a nice weekend.
    You really are determined to make a fool of yourself aren't you? For one thing, this is a Web Forms app, not MVC. Secondly, JavaScript is just a language and can be executed server-side too, e.g. using Node.js. Thirdly, without some sort of server-side technology, be it Web Forms, ASP.NET MVC, Ruby on Rails or whatever, there's nothing to send JavaScript code to the client to be executed there. Your comment is like saying cars rule and engines suck. It's just plain stupid.

  10. #10

    Thread Starter
    New Member daarsk's Avatar
    Join Date
    Jun 2014
    Location
    Melbourne, Australia
    Posts
    13

    Re: Button click and hold

    I do love a good argument... but... I still need a button click and hold function please.

    Thanks

  11. #11
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,344

    Re: Button click and hold

    Quote Originally Posted by daarsk View Post
    I do love a good argument... but... I still need a button click and hold function please.

    Thanks
    Did you read post #5?

  12. #12
    Frenzied Member KGComputers's Avatar
    Join Date
    Dec 2005
    Location
    Cebu, PH
    Posts
    2,020

    Re: Button click and hold

    I do love a good argument... but... I still need a button click and hold function please.
    Have you tried my suggestion? it works and i've tested it. Reference jQuery either downloading the script from the source site or via Nuget.

    That is why Javascript rulez and server side (MVC) sucks!!! :P
    Basically, this is a webforms app
    Yes it is. ASPX with VB code behind
    based from post #3.

    Did you read post #5?
    Last edited by KGComputers; Jun 28th, 2014 at 12:47 AM.
    CodeBank: VB.NET & C#.NET | ASP.NET
    Programming: C# | VB.NET
    Blogs: Personal | Programming
    Projects: GitHub | jsFiddle
    ___________________________________________________________________________________

    Rating someone's post is a way of saying Thanks...

  13. #13

    Thread Starter
    New Member daarsk's Avatar
    Join Date
    Jun 2014
    Location
    Melbourne, Australia
    Posts
    13

    Re: Button click and hold

    I did read post #5, maybe I should have quoted it when posting #7. Sorry.

    I'm not here to upset anyone, but clearly my level of expertise is very very low. So I can understand how this could be frustrating. Sorry again. Also, I'm not very good at this, my posts always seem sarcastic, I can assure you, they are not.

    Anyway, I can see that code on the link you gave (post #5). Unfortunately for me, I know nothing about javascript. Let me quote the code first.
    Code:
    var intervalHandler;
    $('#'+obj_id).mousedown(function() {
      intervalHandler = setInterval(function() { doTheWork(); }, 100);
      return false;
    })
    $('#'+obj_id).mouseup(function() {
      clearInterval(intervalHandler);
    });
    
    function doWork() {
      //I am working here
    }
    Now, firstly, "doTheWork" "DoWork", is that an error?
    Where do I put this code? I was thinking on my aspx page between <script type="text/javascript"> tags. Would that be ok?
    I assume "//I am working here" would be where I put the code to increase Label1 +1, but again, I don't know how to code java, maybe I should learn, that might be a good thing...
    If my button is <asp:Button id="Button1" />, how do I get the button to run the javascript for <asp:Label id="Label1" />?

    I do appreciate all your help and patience.

    Thanks,
    James

  14. #14

    Thread Starter
    New Member daarsk's Avatar
    Join Date
    Jun 2014
    Location
    Melbourne, Australia
    Posts
    13

    Re: Button click and hold

    This is what I have put together so far. But clicking the buttons does nothing...
    Code:
    <asp:Label ID="Label1" runat="server" Text="0" />
    <input type="button" ID="ButtonUp" Value="Up" />
    <input type="button" ID="ButtonDown" Value="Down" />
    
    <script type="text/javascript">
       Var intervalHandler;
       $('ButtonUp').mousedown(function () {
          intervalHandler = setInterval(function () { FactUp(); }, 100);
          return false;
       })
       $('ButtonUp').mouseup(function () {
          clearInterval(intervalHandler);
       });
    
       $('ButtonDown').mousedown(function () {
          intervalHandler = setInterval(function () { FactDown(); }, 100);
          return false;
       })
       $('ButtonDown').mouseup(function () {
          clearInterval(intervalHandler);
       });
    
       function FactUp() {
          var obj = document.getElementById('Label1');
          var num = parseFloat(obj.value);
          if (isNaN(num)) {
             return;
          }
          num = new Integer(num.intValue() + 1);
          obj.value = num;
       }
    
       function FactDown() {
          var obj = document.getElementById('Label1');
          var num = parseFloat(obj.value)
          if (isNaN(num)) {
             return;
          }
          num = new Integer(num.intValue() - 1);
          obj.value = num;
       }
    </script>

  15. #15
    Frenzied Member KGComputers's Avatar
    Join Date
    Dec 2005
    Location
    Cebu, PH
    Posts
    2,020

    Re: Button click and hold

    @daarsk

    I have submitted a solution in our very own asp.net codebank: http://www.vbforums.com/showthread.p...use-down-click. Just follow the instructions and the code.

    KGC
    CodeBank: VB.NET & C#.NET | ASP.NET
    Programming: C# | VB.NET
    Blogs: Personal | Programming
    Projects: GitHub | jsFiddle
    ___________________________________________________________________________________

    Rating someone's post is a way of saying Thanks...

  16. #16
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: Button click and hold

    Quote Originally Posted by daarsk View Post
    I'm afraid my knowledge of Java sits somewhere between 0 and null.
    It's JavaScript not Java. Java is to JavaScript what a car is to a carpet.

  17. #17

    Thread Starter
    New Member daarsk's Avatar
    Join Date
    Jun 2014
    Location
    Melbourne, Australia
    Posts
    13

    Re: Button click and hold

    @KGC
    Thanks, I have now got an idea on what it all means. I can see where I went wrong and my adventure on the learning curve continues

    @Joacim
    Thanks, I understand now. Just goes to show how little someone can know, I now feel like carpet, lol

Posting Permissions

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



Click Here to Expand Forum to Full Width