how can i put if condition for button click event ??

Posted on 2011-02-28
Last Modified: 2012-05-11
i want to know that how can i put if condition for button click event ??

if (this.btnNext.Click += new EventHandler(this.btnNext_Click))
      // some constructor logic here ....

error in above coding ..

what can i do to check whether button is clicked or not ??
Question by:Parth48
LVL 10

Expert Comment

by:Asim Nazir
ID: 35004419

Once button is clicked, it will go to Event handler body and there you can do further processing.

this.btnNext.Click += new System.EventHandler(this.btnNext_Click);

private void btnNext_Click(object sender, EventArgs e)
  // Code for further processing

Open in new window

Let me know if you need further help.

LVL 10

Expert Comment

by:Asim Nazir
ID: 35004433
Using designer, In order to add event for this button, do following:

1. Go to designer
2. Double click the desired button

This will add event handling code to your form.
LVL 19

Expert Comment

by:Manoj Patil
ID: 35004483
Hi, you can check by following way

bool bBtnClicked = false;

    private void cmdOne_Click(object sender, System.EventArgs e) {
        if ((bBtnClicked == true)) {
            MessageBox.Show("This button is clicked already ....");
        else {
            MessageBox.Show("This button is clicked First time ....");
        bBtnClicked = true;

Expert Comment

ID: 35004485
can u please tell us what exactly you want to do?
LVL 10

Accepted Solution

John Claes earned 500 total points
ID: 35004913

You have created a button:
using the folowing code you're adding a event handler upon the Button
this.btnNext.Click += new System.EventHandler(this.btnNext_Click);

An Event handler is called when you perform the action upon the Control :
In this case : Click btnNext

So when you click your button the handler is called that is going to perform the set Method

private void btnNext_Click(object sender, EventArgs e)
  // Code for further processing

What is the difference between this and your code ???
==> The if condition is setting the Click_Event handler and can't be used as condition.

poor beggar


Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

815 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now