Button click event

Discussion in 'ASP .Net' started by James Page, Jan 19, 2010.

  1. James Page

    James Page Guest

    Hi all

    Have a problem setting a button’s click event.

    The button is in a DetailsView row which is nested within a Gridview.
    I need to set its click event to pass a value held in a label within the
    same row and pass that value to a function.

    I have no problems referencing the controls using:

    Dim id as string
    Dim dl As DataList = row.FindControl("DataList1")
    For Each l As DataListItem In dl.Items
    Dim ctlBtn As Button = l.FindControl("btn1")
    Dim ctlLbl As Label = l.FindControl("label1")
    id = ctlLbl.Text
    Next

    But how do i set the click event and do somthing meaningful with the code??

    Any ideas?


    Thanks
    James Page, Jan 19, 2010
    #1
    1. Advertising

  2. On Jan 19, 7:37 pm, James Page <>
    wrote:
    > Hi all
    >
    > Have a problem setting a button’s click event.
    >
    > The button is in a DetailsView row which is nested within a Gridview.
    > I need to set its click event to pass a value held in a label within the
    > same row and pass that value to a function.
    >
    > I have no problems referencing the controls using:
    >
    > Dim id as string
    > Dim dl As DataList = row.FindControl("DataList1")
    > For Each l As DataListItem In dl.Items
    > Dim ctlBtn As Button = l.FindControl("btn1")
    > Dim ctlLbl As Label = l.FindControl("label1")
    > id = ctlLbl.Text
    > Next
    >
    > But how do i set the click event and do somthing meaningful with the code??
    >
    > Any ideas?
    >
    > Thanks


    Hi James,

    Use EventHandler to register the event-handling method
    http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.button.click.aspx

    Hope this helps
    Alexey Smirnov, Jan 19, 2010
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.

Share This Page