How to count button clik event [Resolved]

Posted by Nareyugam under C# on 7/24/2012 | Points: 10 | Views : 25489 | Status : [Member] | Replies : 12
HI all

Is there any two count no of clicks of a button control in C# and Asp.net!


Thanks in Advance

VenkatNaresh


Responses

Posted by: Ranjeet_8 on: 7/24/2012 [Member] [MVP] Gold | Points: 50

Up
0
Down

Resolved

    static int count = 0;  


protected void Button1_Click(object sender, EventArgs e)
{
count++;
Button1.Text=count.ToString();
}


Nareyugam, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Oswaldlily on: 7/24/2012 [Member] Starter | Points: 50

Up
0
Down

Resolved
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If Label1.Text = "Label1" Then
Label1.Text = String.Empty

End If
If Label1.Text = String.Empty Then
Label1.Text = 1
Else
Label1.Text = Convert.ToString(Convert.ToInt32(Label1.Text) + 1)

End If
End Sub


Nareyugam, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Patel28rajendra on: 7/25/2012 [Member] Starter | Points: 50

Up
0
Down

Resolved
Hi

you can store it in View state

R D Patel

Nareyugam, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ranjeet_8 on: 7/25/2012 [Member] [MVP] Gold | Points: 50

Up
0
Down

Resolved
    protected void Page_Load(object sender, EventArgs e)

{
if (!IsPostBack)
ViewState["Count"] = 0;
}
protected void Button1_Click(object sender, EventArgs e)
{
ViewState["count"] = Convert.ToInt32(ViewState["count"]) + 1;
Button1.Text = ViewState["count"].ToString();
}


Nareyugam, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Vuyiswamb on: 7/24/2012 [Member] [MVP] [Administrator] NotApplicable | Points: 25

Up
0
Down
Good Answer @Ranjeet_8

Thank you for posting at Dotnetfunda
[Administrator]

Nareyugam, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Nareyugam on: 7/24/2012 [Member] Starter | Points: 25

Up
0
Down
Thanks ranjeet, i alrdy use this, need some other way..

VenkatNaresh

Nareyugam, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Patel28rajendra on: 7/25/2012 [Member] Starter | Points: 25

Up
0
Down
Hi
To do it Using Java script
refer this link
http://stackoverflow.com/questions/5736860/incrementing-the-count-on-click-of-button

R D Patel

Nareyugam, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Patel28rajendra on: 7/25/2012 [Member] Starter | Points: 25

Up
0
Down
Hi

here is for html

http://answers.yahoo.com/question/index?qid=20080421111558AASBWff

R D Patel

Nareyugam, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ranjeet_8 on: 7/25/2012 [Member] [MVP] Gold | Points: 25

Up
0
Down
You can also use Jquery
Refer this url
http://stackoverflow.com/questions/4701349/jquery-increase-the-value-of-a-counter-when-a-button-is-clicked

Nareyugam, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Nareyugam on: 7/25/2012 [Member] Starter | Points: 25

Up
0
Down
Again Thanku

VenkatNaresh

Nareyugam, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ranjeet_8 on: 7/25/2012 [Member] [MVP] Gold | Points: 25

Up
0
Down
Hi Nareyugam
Mark As Answer if my post helped u.

Nareyugam, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Nareyugam on: 7/29/2012 [Member] Starter | Points: 25

Up
0
Down
Thank you it really helpful

VenkatNaresh

Nareyugam, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response