I have a form where I’m adding TextBox with a [+] button, the first textbox and button is created at runtime, so, the code to define the Click event of the button is (or should be) something like:
AddHandler button1.Click, AddressOf ButtonPlusClick
No problem so far, but the problem is: I need 2 parameters in ButtonPlusClick(): panel ID where I’m going to add textbox, as the page has an extense list of controls and sequence number of last TextBox created, in order to not repeat ID’s in the page.
So here I get lost, all I’ve searched talks about delegates like:
Delegate Sub MySubDelegate(ByVal container As Panel, ByVal nseq As Integer)
Dim msd As MySubDelegate
msd = AddressOf ButtonPlusClick
msd.invoke(Panel1, 3)
But, hey, I’m not invoking now but defining the button1.Click event which must call a function that needs parameters, can you help me or point to some documentation?
(the final result would be a list like, and all this is created by a Class’s code):
[TextBox] [+]
[TextBox] [+]
[TextBox] [+]
)
You could use a
Dictionary(Of String, Int32). The key is the ID of the panel and the value is the count of already createdTextBoxes.Then you can use
FindControl(panelID) to get the reference to yourPanel. You need to recreate the TextBoxes from the count inPage_Loadat the latest. Derive the ID’s from the consecutive number, for example “TextBox_1”, “TextBox_2″… “TextBox_10”, where 10 is theValuein the dictionary for this panel.In the event handler you only have to call the method which creates one textbox and sum up 1 to the dictionary value.