Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simulate a button click within the application (VB.NET)

Tags:

vb.net

Good day,

In my application, I have Private Sub btnSendSMS_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSendMessage.Click in my program.

I would like to simulate a button click of the above within my other sub (an SMS receive detector) when an SMS is received.

How do I do this? I know this is not the best way of doing things but just for the sake of learning. Thanks.

like image 274
Jpeh Noynay Avatar asked May 02 '12 23:05

Jpeh Noynay


People also ask

How do you call a button click event in code behind?

To simulate the button click in code, you simply call the event handler: Button1_Click(object sender, EventArgs e). protected void Page_Load(object sender, EventArgs e) { //This simulates the button click from within your code. Button1_Click(Button1, EventArgs.


2 Answers

You can call the Button.PerformClick method:

btnSendSMS.PerformClick()
like image 144
Jay Riggs Avatar answered Nov 12 '22 00:11

Jay Riggs


You can call the function directly.

btnSendSMS_Click(Me, EventArgs.Empty) 
like image 42
jarchuleta Avatar answered Nov 12 '22 01:11

jarchuleta