Salut Benoit,
If you are creating buttons dynamically, you need to use Addhandler to
create the event and tell it the name of the routine that handles the event.
AddHandler btnBtn.Click, AddressOf displayit
I've pasted in some code below that creates buttons in a loop and adds
handlers for each.
Let us know if it helps?
Ken
Microsoft MVP [ASP.NET]
Toronto
Dim ee As New EventArgs
Private Sub Page_Load _
(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles MyBase.Load
Dim txtBx As TextBox
Dim btnBtn As Button
Dim lblLbl As Label
Dim litLiteral As Literal
Dim intCounter As Integer
For intCounter = 1 To 5
btnBtn = New Button
btnBtn.Text = "Button" & intCounter.ToString
lblLbl = New Label
lblLbl.Text = "Label" & intCounter.ToString
litLiteral = New Literal
litLiteral.Text = "<br>"
PlaceHolder1.Controls.Add(litLiteral)
PlaceHolder1.Controls.Add(lblLbl)
PlaceHolder1.Controls.Add(litLiteral)
ee.Equals(lblLbl)
AddHandler btnBtn.Click, AddressOf displayit
PlaceHolder1.Controls.Add(btnBtn)
PlaceHolder1.Controls.Add(litLiteral)
Next
End Sub
Public Sub displayit(ByVal s As Object, ByVal e As EventArgs)
Dim btn As Button
btn = s
Label1.Text = btn.ClientID & _
": Dynamically Added Link Button is Clicked"
End Sub
<form id="Form1" method="post" runat="server">
<p>
<asp
laceholder id="PlaceHolder1"
runat="server"></asp
laceholder></p>
<p>
<asp:label id="Label1" runat="server">Label</asp:label></p>
</form>
benoit said:
using this usercontrol
-
http://www.denisbauer.com/ASPNETControls/DynamicControlsPlaceholder.aspx -
I manage to create several inputfields and buttons, depending on what user
needs.
works fine
However, I do not find much useable help on recreating eventhandlers for
dynamic generated buttons. All I seem to find is when you know in advance
how
much buttons will be created, which unfortunately is not the case in my
application
anyone an idea ?