locked
vb.net one button to click two buttons RRS feed

  • Question

  • User1298215938 posted

     Protected Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click, Button1.Click, Button2.Click

    how can I have one button to click enter on the another two buttons?

    Thursday, September 10, 2020 6:28 PM

Answers

  • User1535942433 posted

    Hi MOHIIMRAN,

    how can I have one button to click enter on the another two buttons?

    Could you tell us more details of your requirment?I don't understand clearly.I'm guessing that  when you click button3,it will call button2 and button1 click event programmatically.

    Just like this:

    Protected Sub Button3_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button3.Click
            Button2_Click(Sender, e)
            Button1_Click(Sender, e)
    End Sub

    Best regards,

    Yijing Sun

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, September 11, 2020 2:08 AM

All replies

  • User-943250815 posted

    Are you asking how a Button click fires another button click?
    Or you have to have 3 buttons placed at different locations on page and all executing same actions?

    Thursday, September 10, 2020 7:46 PM
  • User475983607 posted

     Protected Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click, Button1.Click, Button2.Click

    how can I have one button to click enter on the another two buttons?

    Your question is rather confusing.  Clicking happens in the browser not the server.  The server code handles the click.  Should we assume the single handler for three buttons does not meet your requirement?  Maybe you want to reuse code?

    Move the 3 click handler bodies to a 3 different methods.  Then simply call the methods from the click handlers however you like.

        Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            Dim m1 As String = Method1()
            Dim m2 As String = Method2()
            Dim m3 As String = Method3()
        End Sub
    
        Protected Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
            Dim m2 As String = Method2()
        End Sub
    
        Protected Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
            Dim m3 As String = Method3()
        End Sub
    
        Protected Function Method1() As String
            Return "Hello"
        End Function
        Protected Function Method2() As String
            Return "World"
        End Function
        Protected Function Method3() As String
            Return "Foo Bar"
        End Function

    Thursday, September 10, 2020 7:52 PM
  • User1535942433 posted

    Hi MOHIIMRAN,

    how can I have one button to click enter on the another two buttons?

    Could you tell us more details of your requirment?I don't understand clearly.I'm guessing that  when you click button3,it will call button2 and button1 click event programmatically.

    Just like this:

    Protected Sub Button3_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button3.Click
            Button2_Click(Sender, e)
            Button1_Click(Sender, e)
    End Sub

    Best regards,

    Yijing Sun

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, September 11, 2020 2:08 AM