Addhandler help

U

UGH

I am adding image buttons dynamically and I need to add event handler when
the user clicks on one of those image buttons which will have different id
for reports.

Here is my code

LnkImage = New ImageButton()
LnkImage.ImageUrl = "~/printer.gif"
LnkImage.ID = "ib" & oArray(1, id)
AddHandler LnkImage.Command, AddressOf NewIbnCommandEvent()
cellItem.Controls.Add(LnkImage)

here is the handler

Private Sub NewIbnCommandEvent(ByVal sender As System.Object, ByVal e As
System.Web.UI.ImageClickEventArgs)
' Will do something here
Reponse.redirect(""~/appt.aspx?appt_id=" & LnkImage.ID")
End Sub

But I get this error message. Argument not specified for parameter 'e' of
'Private Sub NewIbnCommandEvent(sender As Object, e As
System.Web.UI.ImageClickEventArgs)'.

I do not know what to put in between the () AddHandler LnkImage.Command,
AddressOf NewIbnCommandEvent()

Thanks for any help.
 
K

Karl Seguin

Couple things,

first to get rid of the error, simply remove the () after the addressof, so
instead of:
AddHandler LnkImage.Command, AddressOf NewIbnCommandEvent()

do:
AddHandler LnkImage.Command, AddressOf NewIbnCommandEvent

simple, non?


Secondly, if you are going to use Command instead of Click (which you
probably want to in this case), your 2nd parameter needs to be of type
System.Web.UI.WEbControls.CommandEventArgs. ImageclickEventArgs is for the
click event


Lastly, consider using LnkImage.CommandArgument = "ib" & oArray(i,id) and
use e.commandArgument as your parameter in your redirect. This way LnkImage
doesn't have to be declared as a global property - simply scope it where you
create it and forget about it.

Karl
 
U

UGH

I otok out the () but it still gives me the error.

XXXXXXX.aspx.vb(218): Method 'Private Sub NewIbnCommandEvent()' does not
have the same signature as delegate 'Delegate Sub CommandEventHandler(sender
As Object, e As System.Web.UI.WebControls.CommandEventArgs)'.
 
K

Karl Seguin

If you read my original reply, you'll see that I addressed this...it's my
second point.

Karl
 
U

UGH

It is not clear to me but I figured out what you meant however the handler
that I added does not fired when I click on the button.
 
K

Karl Seguin

The linkimage must be added on postback and must have the handler hooked
then. In other words you CAN'T wrap the code in a if not page.ispostback.

Karl
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,989
Messages
2,570,207
Members
46,782
Latest member
ThomasGex

Latest Threads

Top