VB.NET - How do i call the click event of a command button

Asked By Ralph Acido on 17-Aug-06 11:11 PM
Private Sub btnGenerate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGenerate.Click


Given the following code above how to i call that one in vb.net? what are the parameters that i need to supply in order to call the click event? please give a sample code on how to do it.. thanks a lot!
Asked By Sushila Patel on 17-Aug-06 11:26 PM
Check out "The Windows Forms Application Model"
http://samples.gotdotnet.com/quickstart/winforms/doc/WinFormsApplicationModel.aspx
For webform
http://klomdark.servebeer.com:8081/MessageBase2/ReadMessage.aspx?MsgNum=1755

click event of a command button - Asked By J S on 18-Aug-06 01:11 AM

Double check the button in the HTML section and make sure you don't have any hard-wired 

http://www.startvbdotnet.com/controls/button.aspx

http://www.codeworks.it/net/Sysevents.htm

Put in Another Sub - Asked By F Cali on 18-Aug-06 09:44 AM

If I understand correctly what you are trying to do, you want to perform the same steps that your click event does in another place of your program.  If this is the case, I would suggest that you create another method where you will put those commands and just call that method in your click event.  At the same time, you can call that same method somewhere else without invoking the click event.
Calling a button eventhandler - Asked By Jason Hasler on 20-Aug-06 12:48 AM
Of course the button [btnGenerate] calls the procedure but if I am correct you want to call this same procedure from somewhere else.  If so then...

Create a form with two buttons on it.
Make sure their names are the same as the ones shown in code.
[Button1], [Button2]
Copy in the code below and check how it runs.


[CODE]

Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        MessageBox.Show("Button is called from somewhere??")
    End Sub

    ''' <summary>
    ''' Button two on a form to show that the event handler of another button can be called.
    ''' </summary> 
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        ' You could pass the object and event arguments passed to this procedure if required.
        ' Meaning you send the parameters passed to this procedure onto the Button1_Click procedure.
        Button1_Click(sender, e)

        ' You can call a procedure or function that calls the Button1_Click procedure
        CallButton()

    End Sub


    ''' <summary>
    ''' Some procedure in your app somewhere.
    ''' </summary>
    ''' <remarks></remarks>
    Private Sub CallButton()
        ' You can call the Button1_Click procedure passing "nothing" to the parameters.
        Button1_Click(Nothing, Nothing)

    End Sub

End Class

[/CODE]

I hope this is something close to explaining your question.
Prueba esto/Tray it - Asked By Roberto Perezcano on 28-Aug-06 09:46 AM
btnGenerate_Click(Nothing,Nothing)


Private Sub btnGenerate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGenerate.Click 


Buena suerte/Good Look
Roberto Perezcano
thanx - sachin nemade replied to Roberto Perezcano on 14-Jul-09 05:56 AM
btnGenerate_Click(Nothing,Nothing) worked
Andy replied to Jason Hasler on 11-Feb-10 10:51 AM
You HAVE to be kidding me...  Youre presenting THIS as a solution for the guy???

Let me ask you, when you sweep your floor, do you have a constuction company come to your house, lift the house off the foundation, then have a huge helicopter pick up the house and tip it to one side so the dust slides in that direction????

...or do you have the wits to use a broom?  Ya know, simple, elegant.

To programmatically click a button, use ONE line -

BtnMyButton_Click(Nothing, Nothing)  ... thats it, and all you need.

Why write 2000 lines of code, when 1 will do?

Dear Mr. you just saved me... - Nirmalya Khasnobis replied to Roberto Perezcano on 11-Aug-10 06:07 AM
Thanx thanx....a million thanx buddy...
you just saved me from writing 4500 lines of code a second time.....
thanx again....
Nirmalya Khasnobis replied to Andy on 11-Aug-10 06:09 AM
Thanx to you too...
i just got saved from writing 4500 lines of code a second time.....
kanchan replied to Ralph Acido on 06-Mar-11 10:57 PM
on your html code there is a property named onClick just type ur function name which u want to call at that event..
just like in asp.net:
 <asp:button Id="Button1" runat="server" onclick="click.aspx.cs" Text="Ok">
</asp:Button>