Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > responding to an event from a dynamically created control

Reply
Thread Tools

responding to an event from a dynamically created control

 
 
carhip carhip is offline
Junior Member
Join Date: Sep 2008
Posts: 3
 
      09-08-2008
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Affecting a dynamically created drop down from another dynamically created drop down. msimmons ASP .Net 0 07-16-2009 03:17 PM
asp.net -- responding to an event from a dynamically created control carhip Software 0 09-08-2008 08:33 PM
Responding to event from programmatically created button - ASP.NET dinotius@gmail.com ASP .Net 1 09-30-2006 08:04 PM
Managing ViewState of a dynamically created Custom Composite Server Control -(where the original is also dynamically created) dickster ASP .Net Building Controls 0 12-08-2005 09:32 AM
Responding to events in dynamically created web controls JezB ASP .Net Web Controls 2 06-21-2004 06:22 AM



Advertisments