blogspot visit counter

Tuesday, 2 April 2013

how to count number of button clicks in asp.net

how to count number of button clicks in asp.net ?
Introduction:
Here, we will see how to check number of click on button click by the user.When user click on the button automatically increment by one.
Description:
In this article how i can count the user click on button .its a static counter when user refresh the page the counter start from zero. in my previous article i have explained how i can count the total click by the user on button click and display the result in text box.

Html file code as  shown below

Its a simple javascripts code for generate the number on button click by the user

<script type="text/javascript">
    var index = 0;

    function increment(var1) {
        index++;
        if (var1 == 1)
        { document.getElementById('button1').value = index; }
        else
        { document.getElementById('button2').value = index; }

    }
</script>
calling the javascript funtion on button click and display the total click by the user

<form id="form" runat="server">
    <div>
    <input type="button" id="button1" onclick="increment(0)" value="increment"/>
    <input type="button" id="button2" onclick="increment(1)" value="increment again"/>
    </div>
    </form>

Image for show all the complete code as show below
Example show below



Download sample code attached

1 comment:

Related Posts Plugin for WordPress, Blogger...