Dynamic Buttons and Event Handlers, revisited

B

Boban Dragojlovic

The Concept:

I dynamically create an HTML table (with many rows) each with its own
button. When the user clicks on the button, I wan't to know which row's
button they clicked.


The Details:

On the initial pass through a page (e.g. when NOT Page.isPostBack) I read a
SQL table, and for each row in the table I create a dynamic row in an HTML
table, including a button. I also assign an event handler for the new
button

b = New Button
b.Text = "Select"
b.ID = "btnSelect" & iCount
AddHandler b.Click, AddressOf SelectRow

I also record how many buttons I created in the ViewState.

When the page is posted back (within Page_Init), I recreate the buttons,
including the event handler, as follows:

For i = 1 To CInt(ViewState("nbrButtons"))
b = New Button
b.ID = "btnSelect" & i
AddHandler b.Click, AddressOf SelectRow
Next i

Yet in spite of this, I can never get the SelectRow event handler to fire.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,563
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top