PDA

View Full Version : adding button event handler at runtime problems


lee2006
18-04-2007, 02:18 PM
Hi there
I have some text boxs that are created at runtime to hold information from an xml file
This is all fine but i also want to add a delete button at the bottom of each text box created at runtime
the code snipit I am using is
'loop for all text nodes
For i = 0 To stextcount - 1
'create strings and textboxs


Dim titletxt As New TextBox

Dim delbtn As New Button
Dim ttext As New TextBox
'add textbox properties
With titletxt
.Width = 600
.CssClass = "edittitle"
.Text = stitletext(i).InnerText.Trim
End With
With ttext
.Width = 600
.Height = 244
.TextMode = TextBoxMode.MultiLine
.Wrap = True
.Text = stext(i).InnerText.Trim
End With
End If
'add button properties
With delbtn
.CssClass = "delb"
.Text = "Delete"
.ID = "etbutton"
End With


'add control to edit panel

editt_pnl.Controls.Add(titletxt)
editt_pnl.Controls.Add(ttext)
editt_pnl.Controls.Add(delbtn)
AddHandler delbtn.Click, AddressOf delarea_Click ( problem Here)
Next i
This all works fine and the button shows but the click event does not fire when the delete buttons are clicked
my event handler is as follows
'delete button clicked
Protected Sub delarea_Click(ByVal sender As Object, ByVal e As System.EventArgs)
"code here"
End Sub
This code acording to the MSDN site should work
Anyone see what I am doing wrong
I have exsuated all what I know
Thanks any more info just ask
Lee

lee2006
18-04-2007, 06:47 PM
Hi all
Got it fixed in case you wher wondering

I had to change my master page code from the on_load to on_int handler
and then my content page to on_load from on_loaded

All works now witout changing the code

leanrd somthing new wasnt awre of the loading order of pages

Thanks all
Lee