giselleghadyani
giselleghadyani

Reputation: 182

How do I trigger a user control's button click event?

In my web application, I have a user control that has some buttons in it. On another page, I want to load in that control and program what happens when the buttons are clicked. How do I trigger the click event of the button inside my user control?

Upvotes: 1

Views: 1504

Answers (1)

giselleghadyani
giselleghadyani

Reputation: 182

If you have this in your user control code:

<asp:Button ID="Button" Text="Button" runat="server" />


Public Class UserControl

  Public Event ButtonClick()

  Private Sub button_Click(sender As Object, e As EventArgs) handles Button.Click
    Raise Event ButtonClick()
  End Sub

End Class

Then on the page you want to load the user control on you could call the button's click event like this:

<UC:Button ID="UCButton" runat="server" />


Private Sub UCButton_Click() Handles UCButton.ButtonClick
  'write your code here
End Sub

Upvotes: 1

Related Questions