asp.net -- responding to an event from a dynamically created control

Discussion in 'Software' started by carhip, Sep 8, 2008.

  1. carhip

    carhip

    Joined:
    Sep 8, 2008
    Messages:
    2
    I have created a table dynamically, and I create in it several LinkedButton controls.
    I register the Click event with my handling method, but it never gets called.
    Can anyone help with that?
    I would really appreciate it. Thanks.

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    If Not Page.IsPostBack Then
    'header row
    columnHeaders = New CRowData()
    columnHeaders.arrData(0)._textData = "Zero"
    columnHeaders.arrData(1)._textData = "Column Uno"

    'initial row of data
    Dim row1 As New CRowData()
    row1.arrData(0)._textData = "RowUno"
    row1.arrData(1)._textData = "SampleData"

    rows = New List(Of CRowData)
    rows.Add(row1)

    Session("columnHeaders") = columnHeaders
    Session("rows") = rows

    SetupTable()
    End If

    End Sub

    Sub SetupTable()
    Table1.Rows.Clear()

    'add header cells
    Dim rowHeader As New TableRow()
    For i As Integer = 0 To columnHeaders.arrData.Count - 1
    Dim tCell As New TableHeaderCell()
    tCell.Text = columnHeaders.arrData(i)._textData
    rowHeader.Cells.Add(tCell)
    Next

    'add rows to the table
    Table1.Rows.Add(rowHeader)

    For indexRow As Integer = 0 To rows.Count - 1
    'add first row cell (row title)
    Dim thCell As New TableHeaderCell()
    thCell.Text = "text"

    Dim lb As New LinkButton()
    lb.EnableViewState = True
    lb.ID = indexRow.ToString
    lb.PostBackUrl = "default.aspx"
    lb.Text = rows(indexRow).arrData(0)._textData + lb.ID
    AddHandler lb.Click, AddressOf btnEdit_Click
    thCell.Controls.Add(lb)

    Dim row As New TableRow()
    row.Cells.Add(thCell)
    'add the remaining cells
    For indexColumn As Integer = 1 To columnHeaders.arrData.Count - 1
    Dim tCell As New TableCell()
    tCell.Text = rows(indexRow).arrData(indexColumn)._textData
    row.Cells.Add(tCell)
    Next
    Table1.Rows.Add(row)
    Next
    End Sub

    Protected Sub btnEdit_Click(ByVal sender As Object, ByVal e As System.EventArgs)
    columnHeaders = Session("columnHeaders")
    rows = Session("rows")

    'cycle thru the row headers and find the sender

    For index As Integer = 0 To rows.Count - 1
    Dim lb As LinkButton = CType(sender, LinkButton)
    If lb.UniqueID = CType(Table1.Rows(index).Cells(0).Controls(0), LinkButton).UniqueID Then
    lb.Text = "Bingo"
    End If
    Next

    End Sub
    carhip, Sep 8, 2008
    #1
    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.
Similar Threads
  1. krish200
    Replies:
    1
    Views:
    2,181
    fred5152
    Dec 18, 2007
  2. nkamalraj
    Replies:
    1
    Views:
    857
    unholy
    May 28, 2006
  3. alienworkshop
    Replies:
    0
    Views:
    2,123
    alienworkshop
    Aug 17, 2006
  4. dumbrock
    Replies:
    4
    Views:
    574
    dumbrock
    Oct 21, 2004
  5. venkyzealous
    Replies:
    0
    Views:
    1,395
    venkyzealous
    May 10, 2008
Loading...

Share This Page