[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

add onclick event handler to linkbutton

Posted on 2005-04-22
8
Medium Priority
?
6,432 Views
Last Modified: 2008-03-04
i am making a linkbutton dynamic via code ..

dim lnkBtn as new LinkButton

how can I attach a BindGrid() function to the lnkBtn when it is clicked ...

I know you can use OnClick when you declare <asp:LinkButton> in the .aspx page, but i'm dynamically creating the linkbutton and adding it to a control based on certain criteria .. so it's going to call a generic function.

0
Comment
Question by:SeanGraflund
  • 3
5 Comments
 
LVL 23

Expert Comment

by:b1xml2
ID: 13844639
AddHandler lnkBtn.Click, Address lnkBtn_Click

and have the following;

Private Sub lnkBtn_Click(ByVal sender As Object, ByVal e As EventArgs)
   ' code
End Sub

Notice, there's no Handles lnkBtn.Click
0
 
LVL 23

Expert Comment

by:b1xml2
ID: 13844712
errata

AddHandler lnkBtn.Click, AddressOf lnkBtn_Click
0
 
LVL 1

Author Comment

by:SeanGraflund
ID: 13844939
hi,

it doesn't work .. i set a breakpoint at the code, it adds the handler fine when building, then i click on it, it doesn't go to the function, it just loopes through page_load as normal
0
 
LVL 23

Accepted Solution

by:
b1xml2 earned 200 total points
ID: 13845125
where are you adding the dynamic button that's the problem...
upon postback if the button isnt there, the event wont fire..
0
 
LVL 4

Expert Comment

by:fceledon
ID: 13849976
Indeed, use lnkBtn.Command instead of .Click.
Remember to add your own (unique) .ID when creating lnkBtn and recreate the link again at Page_Load time for the link to work.
Also, you need to add for the AddHandler statement.
    Private WithEvents lnkBtn As System.Web.UI.WebControls.LinkButton
fc:)
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses

872 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question