Results 1 to 1 of 1

Thread: Change ASP.NET Label control value using continuous mouse down click

  1. #1

    Thread Starter
    Frenzied Member KGComputers's Avatar
    Join Date
    Dec 2005
    Location
    Cebu, PH
    Posts
    2,020

    Change ASP.NET Label control value using continuous mouse down click

    Here's how to change an asp.net label value on mouse hold. Add/reference jQuery in your asp.net app.

    javascript Code:
    1. <script type="text/javascript" src="Scripts/jquery-2.1.1.min.js"></script>
    2. <script type="text/javascript">
    3.         var intervalHandler;
    4.  
    5.         $(document).ready(function() {
    6.             $('#ButtonUp').mousedown(function() {
    7.                 intervalHandler = setInterval(function() { FactUp(); }, 100);
    8.                 return false;
    9.             });
    10.            
    11.             $('#ButtonUp').mouseup(function () {
    12.                 clearInterval(intervalHandler);
    13.             });
    14.  
    15.             $('#ButtonDown').mousedown(function() {
    16.                 intervalHandler = setInterval(function() { FactDown(); }, 100);
    17.                 return false;
    18.             });
    19.            
    20.             $('#ButtonDown').mouseup(function () {
    21.                 clearInterval(intervalHandler);
    22.             });
    23.         });
    24.        
    25.         function FactUp() {
    26.             var obj = $("#<%= Label1.ClientID %>").text();
    27.             var num = parseFloat(obj);
    28.  
    29.             if (isNaN(num)) {
    30.                 return;
    31.             }
    32.            
    33.             num = parseFloat(num + 1);
    34.             $("#<%= Label1.ClientID %>").text(num);
    35.         }
    36.  
    37.         function FactDown() {
    38.             var obj = $("#<%= Label1.ClientID %>").text();
    39.             var num = parseFloat(obj);
    40.  
    41.             if (isNaN(num)) {
    42.                 return;
    43.             }
    44.  
    45.             num = parseFloat(num - 1);
    46.             $("#<%= Label1.ClientID %>").text(num);
    47.         }
    48.        
    49. </script>

    aspx.
    html Code:
    1. <form id="form1" runat="server">
    2.     <div>
    3.     <input type="button" id="ButtonUp" value="+" />&nbsp;
    4.     <input type="button" id="ButtonDown" value="-" />
    5.     <br/>
    6.     <asp:Label ID="Label1" runat="server" Text="0" />
    7.     </div>
    8.     </form>


    Code Sample: ASP.NET VS 2012


    Reference: Easily do a continuous action on mouse hold using javascript
    Attached Files Attached Files
    Last edited by KGComputers; Jul 4th, 2014 at 11:25 PM.
    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...

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