Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2011-02-28
5
Medium Priority
?
2,776 Views
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 ??
0
Comment
Question by:Parth48
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 10

Expert Comment

by:Asim Nazir
ID: 35004419
Hi,

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.

Asim,
0
 
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.
0
 
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;
    }
0
 
LVL 5

Expert Comment

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

Accepted Solution

by:
John Claes earned 2000 total points
ID: 35004913
@Parth48


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.


Regads
poor beggar



0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

721 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