Vb.net – Send parameter to addhandler


I have a button in a grid that I created programmatically. The button edits some data in a table using data in a hidden column of the grid that the button is in. Normally I send a hidden field the row data using javascript onclientclick of the button then make the changes to the database using that hidden field. But there must be a way to send the addhandler of the button a parameter. This is the code i have to clarify….

Dim btnedit As New ImageButton
    AddHandler btnedit.Click, AddressOf btnedit_Click
    btnedit.ImageUrl = "\images\bttnEditMini.gif"

If e.Row.RowType <> DataControlRowType.Header And e.Row.RowType <> DataControlRowType.Footer Then
End If

here is my Addhandler with its delegate:

Public Delegate Sub ImageClickEventHandler(ByVal sender As Object, ByVal e As ImageClickEventArgs)
Sub btnedit_Click(ByVal sender As Object, ByVal e As ImageClickEventArgs)
//programming stuff
End Sub

How can i send this handler a parameter?

Best Solution

By convention, all event handlers accept two parameters: the sender, and the EventArgs. If you need to send custom information to the listeners, create a new class that inherits from EventArgs and contains the information that you need to communicate.

Check out this article on CodeProject that shows you how to do this.

Related Question