Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Simulating a button click

Posted on 2009-07-03
5
Medium Priority
?
322 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 Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
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…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

604 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