Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Programmatically Assign Events to Control 1

Status
Not open for further replies.

figler

Programmer
Dec 26, 2001
155
US
I am programmatically creating linkbutton controls, but I don't know how to handle events for these controls. I am using VB.NET... any suggestions?

-brad
 
Check out the AddHandler method.
For example

AddHandler MyButton.Click, AddressOf (MySub)



Mark [openup]
 
let me clarify:
i am programmatically creating several linkbuttons on the page. if i use:

sub buttonclick(...) handles mybutton.click
end sub

then the event is only triggered for the last linkbutton that i added (for which the variable 'mybutton' is still handling the linkbutton).

how do i raise the same event for all the buttons????????

-brad
 
thanks. i jumped the gun and replied to my post before i read yours...

addhandler method looks good, but i am having trouble using it. here's what i have - can you tell me what's wrong?:

addhandler(alb.Click,Addressof("btncreateclick"))

----
alb is the linkbutton
btncreateclick is the name of the procedure that i want to handle this event

THANKS SO MUCH
-brad
 
Problem solved. MANY thanks, mark.
I don't understand why AddHandler doesn't work like other procedures in vb.net (didn't i learn that parantheses are *required* for arguments in vb.net?), but here it:

Code:
AddHandler alb.command, AddressOf btncreateclick

alb is the name of the linkbutton
btncreateclick is the name of the procedure that i am using to handle the event

thanks again1
 
No worries.
The parantheses thing confuses me as well. If you are not using VS.net, then it does make things more difficult (VS.net corrects or draws your attention to these things as you type and I guess I've become reliant on it). (If you are not using it, then you can get a 60 day trial version, and once you've used it, you won't want to go back to notepad or Web Matrix or whatever)

Mark [openup]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top