Hello RA,
I just saw your post and I know that this may be a little bit late. The way
you add an event handler to the dynamically created control is as follows:
1. First create a procedure with the exact signature as an event handler
2. After adding the dynamic control, bind this procedure to the dynamic
control
Note: You can have multiple dynamic controls bind to the same event handler.
As an example:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim btnAdd as New Button
Dim bSomeCondition as Boolean = False
If bSomeCondition = True Then
'add the new button to the form
With btnAdd
.ID = "btnAdd"
.Text = "Add"
'any other attributes
End With
WebForm1.Controls.Add btnAdd
'bind this control to an event handler
AddHandler btnAdd.Click, AddressOf btnAddHandler
End If
'code for the handler
Public Sub btnAddHandler(ByVal sender As System.Object, ByVal e As
System.EventArgs)
' your code goes here
End Sub
Hope this helps.
End Sub
"RA" wrote:
This is what I am doing.
Private Sub PopulateTable()
Dim tRow as New TableRow
Dim tCell as new TableCell
Dim btnAdd As New Button
With btnAdd
.ID = "AddLink"
.Enabled = False
.Font.Bold = True
.Font.Underline = True
.ForeColor = System.Drawing.Color.Blue
.BackColor = System.Drawing.Color.Transparent
.BorderStyle = BorderStyle.None
.Attributes("onClick") = "AddRCode();"
End With
tCell.Controls.Add(btnAdd)
tRow.Cells.Add(tCell)
TableTest.Rows.Add(tRow)
' Also have code to add more data.
End Sub
Public Sub AddItem()
'
dim Test as String
Test = "Testing OnClcik"
End Sub
"Alex" <al**@nospam.net> wrote in message
news:en**************@TK2MSFTNGP11.phx.gbl... Sorry, I am not sure what you mean. The code I gave you is what you need
for
your client side page's control to post back to the code behind. You'll
notice the asp:Button is runat=server, so it will post back to your
page.ascx.vb, where you can write your OnCommand eventhandler,
CommandBtn_Click. When you specify the runat=server, your controls will
trigger the code behind.
This was not javascript at all. The code behind had C# signatures, but you
can change them to VB. If you need more clarification, go here...
ms-help://MS.VSCC.2003/MS.MSDNQTR.2003JUL.1033/cpref/html/frlrfSystemWebUIWe
bControlsButtonClassOnCommandTopic.htm
--
Alex Mueller