B
BluDog
Hi
I am trying to test dynamically created controls, to do this i have
added a placeholder to a WbForm and added the following code behind:
Private Property Count() As Integer
Get
If ViewState("Count") Is Nothing Then ViewState("Count") = 1
Return CType(ViewState("Count"), Integer)
End Get
Set(ByVal Value As Integer)
ViewState("Count") = Value
End Set
End Property
Private Sub Page_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
If Not IsPostBack Then AddButton()
End Sub
Private Sub button_Click(ByVal sender As Object, ByVal e As EventArgs)
AddButton()
End Sub
Private Sub AddButton()
Dim button As New Button
button.Text = "Button" & Count.ToString
button.ID = "Button" & Count.ToString
AddHandler button.Click, AddressOf button_Click
PlaceHolder1.Controls.Add(button)
Count += 1
End Sub
What i would expect is a button to be added to the placeholder during
the first load of the page, then each time the button is cllicked
another button to be added to the form.
However the original button is added in the load event, but the click
event is never handled on the dynamically created buttons, so on
postbacks no buttons are shown.
Can anyone explain how to acheive what i am afer here?
Thanks
Blu.
I am trying to test dynamically created controls, to do this i have
added a placeholder to a WbForm and added the following code behind:
Private Property Count() As Integer
Get
If ViewState("Count") Is Nothing Then ViewState("Count") = 1
Return CType(ViewState("Count"), Integer)
End Get
Set(ByVal Value As Integer)
ViewState("Count") = Value
End Set
End Property
Private Sub Page_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
If Not IsPostBack Then AddButton()
End Sub
Private Sub button_Click(ByVal sender As Object, ByVal e As EventArgs)
AddButton()
End Sub
Private Sub AddButton()
Dim button As New Button
button.Text = "Button" & Count.ToString
button.ID = "Button" & Count.ToString
AddHandler button.Click, AddressOf button_Click
PlaceHolder1.Controls.Add(button)
Count += 1
End Sub
What i would expect is a button to be added to the placeholder during
the first load of the page, then each time the button is cllicked
another button to be added to the form.
However the original button is added in the load event, but the click
event is never handled on the dynamically created buttons, so on
postbacks no buttons are shown.
Can anyone explain how to acheive what i am afer here?
Thanks
Blu.