blogspot visit counter

Monday 1 April 2013

Count the number of times a submit button has been clicked

Count the number of times a submit button has been clicked

Count the number of times a submit button has been clicked

Introduction
  How i can find the user click on submit button in multipal time

GUI Html Code As Shown Below

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="counter.aspx.cs" Inherits="counter" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
  
        <asp:Button ID="Button1" runat="server" onclick="Button1_Click"
            Text="counter" />
&nbsp; Show Total Click of Particular User
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
  
    </div>
    </form>
</body>
</html>

From Image as shown below
On Button Click Couter Code Behind 
static int count = 0; 
protected void Button1_Click(object sender, EventArgs e)
    {
        count++;
        int totalcount = count;
        TextBox1.Text = totalcount.ToString();
    }

Output as shown below

Download sample code attached







------------------------------------------------------------------------------------------------------------------------
How to count character of TextBox in ASP.NET
Introduction:
In this article i will count the how many character in text box enter by the user.
Description: 
In my previous article i have explained how i can count the total no of click on button by the user. and another article i have explained and provide the full source code for display the total click by the user on button in text box.
Here, we will see how to check number of character has been inserted in the TextBox. A TextBox Which has max length 120 character and we insert a character in TextBox max length will bedisplay 119 characters. When We enter 120 characters in the TextBox that will be the Max length. Drag and drop a TextBox on the page. Select TextBox and press F4 to property window.

Code For java Scripts as shown below

<style type="text/css">

        .valid

        {
    background-color: #FFFFFF;
            color: #000000;
        }   
        .invalid
        {
            background-color: #FFCCCC;
            color: #ff0000;
        }
    </style>
    <script type="text/javascript">
        function textCounter1(field, maxlimit)
         {
             if (field.value.length > maxlimit)
           {
                field.value = field.value.substring(0, maxlimit);
                document.getElementById('message').className = "invalid";
                document.getElementById('message').focus();
            }
            else
                {
                document.getElementById('message').className = "valid";

                }
        }

        function textCounter(field, countfield, maxlimit) {

            if (field.value.length > maxlimit) // if too long then trim it!
                field.value = field.value.substring(0, maxlimit);
            else
                countfield.value = maxlimit - field.value.length;
        }

    </script>

From Html Code Shown Below 

<form  id="form" runat="server">
    <div style="text-align: center">
    <asp:TextBox ID="message" runat="server" name="message" onkeydown="textCounter(this.form.message,this.form.remLen,120)"

        onkeyup="textCounter1(this.form.message, 120)" class="validentry"

        Height="101px" TextMode="MultiLine" Width="228px"></asp:TextBox>

    <br />
    <input name="remLen" size="5" maxlength="5" value="120" />Character is remaing
  
    </div>
    </form>


Output windows as shown below

Download sample code attached


No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...