Less Than Dot is a community of passionate IT professionals and enthusiasts dedicated to sharing technical knowledge, experience, and assistance. Inside you will find reference materials, interesting technical discussions, and expert tips and commentary. Once you register for an account you will have immediate access to the forums and all past articles and commentaries.
ASP.NET: Add dynamic controls with events
From Wiki
Summary: Add dynamic controls and associate an event with an existing function
Need help with ASP.NET? Come and ask a question in our ASP.NET Forum
- Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
- Dim btn As Button
- For i As Integer = 0 To 10
- btn = New Button
- btn.Text = "Button" & i
- btn.ID = "Button" & i
- AddHandler btn.Click, AddressOf btn_Click
- MyPanel.Controls.Add(btn)
- Next
- End Sub
- Protected Sub btn_Click(ByVal sender As Object, ByVal e As System.EventArgs)
- Response.Write("You clicked " & CType(sender, Button).ID)
- End Sub
This Hack is part of the ASP.NET Hacks collection



LTD Social Sitings
Note: Watch for social icons on posts by your favorite authors to follow their postings on these and other social sites.