Originally Posted by alykins
By "dynamic" I mean that I don't have to put <asp:Button> to my form. Add button created dynamically on page load, Count and Remove on Add click and so on.
Any way I managed to get buttons created dynamically but now I bumped into another problem. I can't seem to get Count and Remove buttons working. They just removes themselves (it's fine with Remove button but Count should add +1 to label value).
Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs)
Dim btn As New Button()
btn.ID = "btn"
btn.Text = "Add"
AddHandler btn.Click, AddressOf btn_Click
Sub btn_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Dim btn1 As New Button()
btn1.ID = "btn1"
btn1.Text = "Count"
AddHandler btn1.Click, AddressOf btn1_Click
Dim btn2 As New Button()
btn2.ID = "btn2"
btn2.Text = "Remove"
AddHandler btn2.Click, AddressOf btn2_Click
Label1.Text = "0"
Sub btn1_Click(ByVal sender As Object, ByVal e As EventArgs)
Label1.Text += 1
Sub btn2_Click(ByVal sender As Object, ByVal e As EventArgs)
<head id="Head1" runat="server">
<form id="form1" runat="server">
<asp:PlaceHolder ID="PlaceHolder1" runat="server" /><br />
<asp:PlaceHolder ID="PlaceHolder2" runat="server" /><br />
<asp:Label runat="server" ID="Label1" />