Webcontrol Event Handler Not working

R

rotomd

The problem is pretty simple.. I want to create a dynamic LinkButton
and add an event handler. Here's my code:

[vb]
Protected WithEvents oLinkButton as linkbutton
Private Sub populateForm()
dim oRow as tablerow
dim oCell as tablecell
dim oDate as datetime

oCell = new tablecell
oLinkButton = new LinkButton
oLinkButton.text = "Delete"
oLinkButton.id = "lbDel"
AddHandler oLinkButton.Click, New System.EventHandler(AddressOf
delTid)
oCell.Controls.add(oLinkButton)
oRow.cells.add(oCell)
tidTable.rows.add(oRow)
End Sub

Private sub delTid(byVal sender As Object, byVal e As System.EventArgs)
handles oLinkButton.Click
response.write ("DELETE Clicked")
End Sub

[end code]
The page renders fine, no errors. Yet when I click on the Delete link,
it posts back, but never writes hits the delTid sub. Any help would be
greatly appreciated. Thanks!

-mike
 
R

rotomd

I figured out what was happening. The syntex was correct, or at least
workable. (I guess the handles part was not necessary, although it did
not cause any errors)

The issue was where the control was being created and added in my code.
When the page submited, that section of the code where the control was
being created would not get hit and therefor the event handler was
never recreated causing the event sub not run on postback. By putting
that code in the page_load sub, everything worked correctly.
 

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,994
Messages
2,570,222
Members
46,809
Latest member
moe77

Latest Threads

Top