?
Solved

Simulating a button click

Posted on 2009-07-03
5
Medium Priority
?
314 Views
Last Modified: 2013-12-17
Hello,
What is a correct way of programmatically simulating a button click?

I know that I can do this:

this.Button1_Click( null, null );

but I have a feeling that there is another better way of doing it, but I can't remember if there actually is.

Would appreciate your help,
Thanks
0
Comment
Question by:Yurich
[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
  • 2
  • 2
5 Comments
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 24776151
Not sure about WebForms, but in WinForms you use:

    Button1.PeformClick();
0
 
LVL 3

Accepted Solution

by:
khdani earned 2000 total points
ID: 24776191
it's not a good thing simulating that way a button click, it's better to put all your "click" code in some function which you call in button click handler, and then you can call this function also from other places in code.

anyway, you can do this
this.Button1_Click(this, new EventArgs()); - it's good as long as you don't need the EventArgs object
0
 
LVL 21

Author Closing Comment

by:Yurich
ID: 31599726
Thanks, I did end up doing a function and calling it from a button click and from another method. Just initially it was simpler to initiate a button click.
0
 
LVL 21

Author Comment

by:Yurich
ID: 24807536
2Idle Mind: oh, and by the way, there is no PerformClick in web apps unfortunatelly ;)
0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 24809110
Gotcha...I wasn't sure...which is why I put the disclaimer on it.  I'm a WinForms guy!  =)

Glad you've got a working solution.
0

Featured Post

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

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

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

762 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