Tech Off Post

Single Post Permalink

View Thread: Attaching events to objects created in code-behind...
  • User profile image
    Rotem Kirshenbaum

    jsampsonPC wrote:
    AddHandler is working gloriously! I am unable to pass values through as parameters though - since this AddHandler wants a subroutine with no parenthesis, how do I pass values through during the call?

    I'm building a large table that looks similar to:

    edit / del || ProductTitle || $0.00
    edit / del || ProductTitle || $0.00
    edit / del || ProductTitle || $0.00

    Where 'edit' and 'del' are LinkButtons that need to post back to the page, call a WebService, and report exactly which product to edit, or delete. So I was trying to pass the ProductID and the OrderID through in the AddHandler...

    ' Add our events to our buttons

    AddHandler deltLink.Click, AddressOf deleteProduct(dr("StandingOrderID"), dr("StandingProductID"))

    Public Sub deleteProduct(ByVal OrderID As Integer, ByVal ProductID As Integer)

    Page.Title = "Deleted " & ProductID.ToString()

    End Sub



    Couple of things:
    1) The Click event handler has to be with the right signature (gets Object sender, EvenetArgs e)
    2) You don't pass parameters in the event binding. Your event handler should get them in it's method body (Sorry it's in C#, my VB is rusty):

    private void button_click(object sender, EventArgs e)
    {
    // Get the right parameters from somewhere...
       int orderId = ...;
       int productId = ...;

       DeleteProduct(orderId , productId);
    }

    3) Why don't you use the GridView capabilities ? It has an edit / delete/ update column etc. Why not use it ?

    Hope this helps you.