When the user clicks a radio button it creates a postback where I add a button control dynamically. My problem is I cannot get the dynamically added button to work with on an click event. The button was created in code behind page.
[color=Blue]Public Sub rosterAddControls()
Dim myBtn As New Button()
myBtn.Style.Item("z-index") = "100"
myBtn.Style.Item("position") = "absolute"
myBtn.Style.Item("top") = (x - 30) & "px"
myBtn.Style.Item("left") = y & "px"
myBtn.ID = "myBtn"
myBtn.Text = "Button 8974"
myBtn.OnClientClick = "myBtn_Click()"
This above code works fine and the button myBtn is displayed when above method is called.
From the help forms that I have read, I gathered I needed to make an AddHandler statement in the Page_Init as shown below.
[color=Blue] Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
AddHandler myBtn.Click, AddressOf myBtn_Click
Lastly, I have created a method that should be called when myBtn is clicked. But the below method is never called.
[color=Blue] Protected Sub myBtn_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Dim test As String
test = "this is a test "
Can someone please help me get the dynamically added button myBtn to fire a onClick event.
0 · ·