Let's say I do something like this:
Dim b As Button = new Button()
b.ID="calculateButton"
b.Text="Calculate!"
Me.Page.Controls.AddControl(b)
Now, what if I wanted to define the subroutine that would fire whenthat button was clicked? If I was adding it directly in the aspxpage, I might do this:
<asp:Button ID="calculateButton" text="Calculate!" runat="server"onClick="calculateSubroutine" />
But if I'm adding the control to the page dynamically, how would I accomplish this?
AddHandler b.Click, AddressOf b_Click
Sub b_Click(ByVal Sender As Object, ByVal e As EventArgs)
' handle the click
End Sub
you need to add some code to the event where the button is created like this:
addhandler b.click, addressof b_Click,
private sub b_Click(byval sender as object, byval e as system.eventargs) handles b.click
'code for click procedure here
end sub
*make sure the name of the sub procedure exactly matches the name you put in the addressof statement.
smtraber
0 comments:
Post a Comment