Solved

Simulating a button click

Posted on 2009-07-03
5
307 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 500 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

Tutorials alone can't teach real engineering

So we built better training tools.

-Hands-on Labs
-Instructor Mentoring
-Scenario-Based Tests
-Dedicated Cloud Servers

All at your fingertips. What are you waiting for?

Question has a verified solution.

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

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

705 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