ImageButton has not onClick method

T

tshad

I was trying to change my asp:button to asp:ImageButton, but got a message
saying that ImageButton does not have an onClick function.

How do I get the ImageButton call a function?

Thanks,

Tom.
 
K

Ken Cox [Microsoft MVP]

Hi Tom.

If you're talking about the server-side Click event then the signature would
look like this:

Private Sub ImageButton1_Click _
(ByVal sender As System.Object, _
ByVal e As System.Web.UI.ImageClickEventArgs) _
Handles ImageButton1.Click

End Sub

Is that what you meant?

Ken
Microsoft MVP [ASP.NET]
 
T

tshad

Ken Cox said:
Hi Tom.

If you're talking about the server-side Click event then the signature
would look like this:

Private Sub ImageButton1_Click _
(ByVal sender As System.Object, _
ByVal e As System.Web.UI.ImageClickEventArgs) _
Handles ImageButton1.Click

End Sub

Is that what you meant?

Here is an asp:Button line with the onClick method

<asp:Button ID="CollapseAll" text="Collapse All"
runat="server" Font-Size="2" onClick="collapseAll_click" Width="16"
Height="16" AlternateText="Click here to see
details"></asp:Button>&nbsp;&nbsp;

If you take the following line:
<asp:ImageButton ID="ExpandButton" runat="server"
Font-Size="2" ImageUrl="../images/expand.jpg" Width="16" Height="16"
CommandName="Select" AlternateText="Click here to see
details"></asp:ImageButton>

And change it to:

<asp:ImageButton ID="ExpandButton"
onClick="ExpandButton_click" runat="server" Font-Size="2"
ImageUrl="../images/expand.jpg" Width="16" Height="16" CommandName="Select"
AlternateText="Click here to see details"></asp:ImageButton>

You get the following message:
Compilation Error
Description: An error occurred during the compilation of a resource required
to service this request. Please review the following specific error details
and modify your source code appropriately.

Compiler Error Message: BC30408: Method 'Public Sub
ExpandButton_click(sender As Object, e As System.EventArgs)' does not have
the same signature as delegate 'Delegate Sub ImageClickEventHandler(sender
As Object, e As System.Web.UI.ImageClickEventArgs)'.

Thanks,

Tom
Ken
Microsoft MVP [ASP.NET]


tshad said:
I was trying to change my asp:button to asp:ImageButton, but got a message
saying that ImageButton does not have an onClick function.

How do I get the ImageButton call a function?

Thanks,

Tom.
 
L

Lau Lei Cheong

Because the EventHandler of ImageButton is not System.EventHandler.
You have to change at InitializeComponent(), from ExpandButton.OnClick +=
new System.EventHandler(ExpandButton_click) to ExpandButton.Click += new
ImageClickEventHandler(ExpandButton_click);

And then the function declaration to private void
ExpandButton_click(object sender, System.Web.UI.ImageClickEventArgs e)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

tshad said:
Ken Cox said:
Hi Tom.

If you're talking about the server-side Click event then the signature
would look like this:

Private Sub ImageButton1_Click _
(ByVal sender As System.Object, _
ByVal e As System.Web.UI.ImageClickEventArgs) _
Handles ImageButton1.Click

End Sub

Is that what you meant?

Here is an asp:Button line with the onClick method

<asp:Button ID="CollapseAll" text="Collapse All"
runat="server" Font-Size="2" onClick="collapseAll_click" Width="16"
Height="16" AlternateText="Click here to see
details"></asp:Button>&nbsp;&nbsp;

If you take the following line:
<asp:ImageButton ID="ExpandButton" runat="server"
Font-Size="2" ImageUrl="../images/expand.jpg" Width="16" Height="16"
CommandName="Select" AlternateText="Click here to see
details"></asp:ImageButton>

And change it to:

<asp:ImageButton ID="ExpandButton"
onClick="ExpandButton_click" runat="server" Font-Size="2"
ImageUrl="../images/expand.jpg" Width="16" Height="16" CommandName="Select"
AlternateText="Click here to see details"></asp:ImageButton>

You get the following message:
Compilation Error
Description: An error occurred during the compilation of a resource required
to service this request. Please review the following specific error details
and modify your source code appropriately.

Compiler Error Message: BC30408: Method 'Public Sub
ExpandButton_click(sender As Object, e As System.EventArgs)' does not have
the same signature as delegate 'Delegate Sub ImageClickEventHandler(sender
As Object, e As System.Web.UI.ImageClickEventArgs)'.

Thanks,

Tom
Ken
Microsoft MVP [ASP.NET]


tshad said:
I was trying to change my asp:button to asp:ImageButton, but got a message
saying that ImageButton does not have an onClick function.

How do I get the ImageButton call a function?

Thanks,

Tom.
 

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

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top