When you run off of 'dynamically created controls' two things have to happen.
They have to be recreated identically each time.
They have to be 'found'
so for instance if you insert a 'label' into a page.
You do (simple version)
sub page load()
dim myLabel as new label
dim mylabel.id = "mylabel"
myLabel.text = "hello world"
page.controls.add(mylabel)
end sub
It is loaded, and will be recreated each time.
Now to handle that control you have to do:
sub button_click() handles button1.click 'Again simplified
dim _label as label
_label = page.findcontrol("myLabel")
response.write "Labels text is:" & _label.text
end sub
Now, if you dynamically add a button you also need to have a handler function with the same args as a real button so.
dim mybutton as new button
mybutton.text = "Click me"
addhandler mybutton.click, addressof myFunc
public sub myFunc(sender as ...., e as eventa....) 'Has to be a valid button/onclick function
response.write "button clicked"
end sub
The best way to make sure your function is correct is to drag out a button, then go to its onclick event in the code view, and copy and paste its code. For reference a valid button code is like this.
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
dim mybutton as new button
mybutton.text = "click me"
addhandler mybutton.click, addressof btnSubmit_Click
end sub
Private Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs)
response.write "I was clicked"
end sub
|