Search options:
Page last updated at 9:8, 30 July 2009

How to programmatically set onclick for a button or linkbutton in asp

Author
aspsimon
ASP.NET programmer, developing websites and applications for clients mainly in the UK.
Document quality
No reviews.
114 words 114 words
Not checked bt nenmo nenmo checked
After trawling Google for hours I finally worked our a solution to the old problem of accessing the onclick server side event when programmatically creating a linkbutton or button with ASP.NET VB.

To do this we need to use AddHandler. Please see the code example below.
I have a link button called LBTN_pageAction and I want to programmically assign the onclick event with 'LinkButton_onclick' in the code behind.

This is how I'd do it:

AddHandler

 

LBTN_pageAction.Click, AddressOf LinkButton_onlclick

It's that simple.

Hope this saves you the trouble of searching for hours!!

Cheers.

 

Share |
Would you recommend this article? Yes