Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Addhandler help

Reply
Thread Tools

Addhandler help

 
 
UGH
Guest
Posts: n/a
 
      11-29-2004
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.




 
Reply With Quote
 
 
 
 
Kumar Reddi
Guest
Posts: n/a
 
      11-29-2004

Hi,
Please remove the parenthesis in the AddHandler code for the eventhandler,
your code should be

AddHandler LnkImage.Command, AddressOf NewIbnCommandEvent

instead of

AddHandler LnkImage.Command, AddressOf NewIbnCommandEvent()

For more information take a look at the following microsoft link

http://msdn.microsoft.com/library/de...BSpec8_6_2.asp

Good Luck

--
Kumar Reddi
http://kumarreddi.blogspot.com

"UGH" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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.
>
>
>
>



 
Reply With Quote
 
 
 
 
Karl Seguin
Guest
Posts: n/a
 
      11-29-2004
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
--
MY ASP.Net tutorials
http://www.openmymind.net/


"UGH" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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.
>
>
>
>



 
Reply With Quote
 
UGH
Guest
Posts: n/a
 
      11-30-2004
I otok out the () but it still gives me the error.

XXXXXXX.aspx.vb(21: 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)'.



"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
wrote in message news:%23Lcs$(E-Mail Removed)...
> 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
> --
> MY ASP.Net tutorials
> http://www.openmymind.net/
>
>
> "UGH" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> 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.
>>
>>
>>
>>

>
>



 
Reply With Quote
 
Karl Seguin
Guest
Posts: n/a
 
      11-30-2004
If you read my original reply, you'll see that I addressed this...it's my
second point.

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/


"UGH" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> I otok out the () but it still gives me the error.
>
> XXXXXXX.aspx.vb(21: 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)'.
>
>
>
> "Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
> wrote in message news:%23Lcs$(E-Mail Removed)...
> > 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
> > --
> > MY ASP.Net tutorials
> > http://www.openmymind.net/
> >
> >
> > "UGH" <(E-Mail Removed)> wrote in message
> > news:(E-Mail Removed)...
> >> 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.
> >>
> >>
> >>
> >>

> >
> >

>
>



 
Reply With Quote
 
UGH
Guest
Posts: n/a
 
      11-30-2004
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.



"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
wrote in message news:%(E-Mail Removed)...
> If you read my original reply, you'll see that I addressed this...it's my
> second point.
>
> Karl
>
> --
> MY ASP.Net tutorials
> http://www.openmymind.net/
>
>
> "UGH" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> I otok out the () but it still gives me the error.
>>
>> XXXXXXX.aspx.vb(21: 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)'.
>>
>>
>>
>> "Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
>> wrote in message news:%23Lcs$(E-Mail Removed)...
>> > 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
>> > --
>> > MY ASP.Net tutorials
>> > http://www.openmymind.net/
>> >
>> >
>> > "UGH" <(E-Mail Removed)> wrote in message
>> > news:(E-Mail Removed)...
>> >> 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.
>> >>
>> >>
>> >>
>> >>
>> >
>> >

>>
>>

>
>



 
Reply With Quote
 
Karl Seguin
Guest
Posts: n/a
 
      11-30-2004
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

--
MY ASP.Net tutorials
http://www.openmymind.net/


"UGH" <(E-Mail Removed)> wrote in message
news:u$(E-Mail Removed)...
> 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.
>
>
>
> "Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
> wrote in message news:%(E-Mail Removed)...
> > If you read my original reply, you'll see that I addressed this...it's

my
> > second point.
> >
> > Karl
> >
> > --
> > MY ASP.Net tutorials
> > http://www.openmymind.net/
> >
> >
> > "UGH" <(E-Mail Removed)> wrote in message
> > news:(E-Mail Removed)...
> >> I otok out the () but it still gives me the error.
> >>
> >> XXXXXXX.aspx.vb(21: 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)'.
> >>
> >>
> >>
> >> "Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
> >> wrote in message news:%23Lcs$(E-Mail Removed)...
> >> > 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
> >> > --
> >> > MY ASP.Net tutorials
> >> > http://www.openmymind.net/
> >> >
> >> >
> >> > "UGH" <(E-Mail Removed)> wrote in message
> >> > news:(E-Mail Removed)...
> >> >> 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.
> >> >>
> >> >>
> >> >>
> >> >>
> >> >
> >> >
> >>
> >>

> >
> >

>
>



 
Reply With Quote
 
UGH
Guest
Posts: n/a
 
      11-30-2004
got it, wow this was a little tuff for me to grasp.


Thanks

"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
wrote in message news:%(E-Mail Removed)...
> 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
>
> --
> MY ASP.Net tutorials
> http://www.openmymind.net/
>
>
> "UGH" <(E-Mail Removed)> wrote in message
> news:u$(E-Mail Removed)...
>> 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.
>>
>>
>>
>> "Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
>> wrote in message news:%(E-Mail Removed)...
>> > If you read my original reply, you'll see that I addressed this...it's

> my
>> > second point.
>> >
>> > Karl
>> >
>> > --
>> > MY ASP.Net tutorials
>> > http://www.openmymind.net/
>> >
>> >
>> > "UGH" <(E-Mail Removed)> wrote in message
>> > news:(E-Mail Removed)...
>> >> I otok out the () but it still gives me the error.
>> >>
>> >> XXXXXXX.aspx.vb(21: 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)'.
>> >>
>> >>
>> >>
>> >> "Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME
>> >> net>
>> >> wrote in message news:%23Lcs$(E-Mail Removed)...
>> >> > 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
>> >> > --
>> >> > MY ASP.Net tutorials
>> >> > http://www.openmymind.net/
>> >> >
>> >> >
>> >> > "UGH" <(E-Mail Removed)> wrote in message
>> >> > news:(E-Mail Removed)...
>> >> >> 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.
>> >> >>
>> >> >>
>> >> >>
>> >> >>
>> >> >
>> >> >
>> >>
>> >>
>> >
>> >

>>
>>

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
ImageButton addhandler not firing ! Tee ASP .Net 1 02-18-2004 04:00 PM
AddHandler question Craig Buchanan ASP .Net 3 02-12-2004 06:00 PM
Event AddHandler Kay ASP .Net 2 02-03-2004 07:02 PM
Re: Help w/AddHandler (Not Firing Off) Natty Gur ASP .Net 1 08-11-2003 03:06 PM
Help w/AddHandler (Not Firing Off) Jeffrey A. Voigt ASP .Net 3 08-11-2003 04:53 AM



Advertisments