Quote:
Originally Posted by alykins
what is it that you are trying to make 'dynamic'? are you just trying to do one button call? you can do that by giving it command arguments and casting the object as a button and switching on the argument- if you are talking about on the client end, simple answer is you can't without javascript, in which case this would move to either JS or AJAX section.
|
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).
Code:
<script runat="server">
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
PlaceHolder1.Controls.Add(btn)
End Sub
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
PlaceHolder2.Controls.Add(btn1)
Dim btn2 As New Button()
btn2.ID = "btn2"
btn2.Text = "Remove"
AddHandler btn2.Click, AddressOf btn2_Click
PlaceHolder2.Controls.Add(btn2)
Label1.Text = "0"
End Sub
Sub btn1_Click(ByVal sender As Object, ByVal e As EventArgs)
Label1.Text += 1
End Sub
Sub btn2_Click(ByVal sender As Object, ByVal e As EventArgs)
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>ASP.NET TEST</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:PlaceHolder ID="PlaceHolder1" runat="server" /><br />
<asp:PlaceHolder ID="PlaceHolder2" runat="server" /><br />
<asp:Label runat="server" ID="Label1" />
</div>
</form>
</body>
</html>