Question about ImageButton Event

A

angus

Dear all,

I know that i can add a button with oncommand event "ImageButton_Command" by
using the asp:ImageButton tag in the aspx code.

<asp:ImageButton id="imagebutton1" runat="server"
AlternateText="Sort Ascending"
ImageUrl="images/pict.jpg"
OnCommand="ImageButton_Command"
CommandName="Sort"
CommandArgument="Ascending"/>

But i have problem if i add that button in the codebehind,


Protected WithEvents imagebutton1As System.Web.UI.WebControls.ImageButton

ibtnSetup = New ImageButton

ibtnSetup.ImageUrl() = "icon-setup.gif"

ibtnSetup.CausesValidation = False

ibtnSetup.CommandArgument = drRack.Item("LOCATION_ID")

Protected Sub ibtnSetup_Click(ByVal sender As Object, ByVal e As
CommandEventArgs) Handles ibtnSetup.Command

Console.Write(e.CommandArgument)

End Sub


However, i cannot fire the event by adding the button in the codebehind,
what's wrong with that?

Thank you for your advices.

Regards,
Angus
 
A

avnrao

you need to add this event handler..

this.ImageButton1.Click += new
System.Web.UI.ImageClickEventHandler(this.ibtnSetup_Click);

Av.
 
H

Harry

i am using VB.net
this.ImageButton1.Click += new
System.Web.UI.ImageClickEventHandler(this.ibtnSetup_Click);

i know that i have to use above statement if i am using c#.

what if VB.net?
 

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,769
Messages
2,569,582
Members
45,069
Latest member
SimplyleanKetoReviews

Latest Threads

Top