By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,313 Members | 2,798 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,313 IT Pros & Developers. It's quick & easy.

ImageButton has not onClick method

P: n/a
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.
Nov 18 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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]
"tshad" <ts**********@ftsolutions.com> wrote in message
news:OT**************@TK2MSFTNGP10.phx.gbl...
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.


Nov 18 '05 #2

P: n/a
"Ken Cox [Microsoft MVP]" <BA************@sympatico.ca> wrote in message
news:uc**************@TK2MSFTNGP12.phx.gbl...
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" <ts**********@ftsolutions.com> wrote in message
news:OT**************@TK2MSFTNGP10.phx.gbl...
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.

Nov 18 '05 #3

P: n/a
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" <ts**********@ftsolutions.com> bl
news:%2****************@TK2MSFTNGP15.phx.gbl g...
"Ken Cox [Microsoft MVP]" <BA************@sympatico.ca> wrote in message
news:uc**************@TK2MSFTNGP12.phx.gbl...
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" <ts**********@ftsolutions.com> wrote in message
news:OT**************@TK2MSFTNGP10.phx.gbl...
I was trying to change my asp:button to asp:ImageButton, but got a messagesaying that ImageButton does not have an onClick function.

How do I get the ImageButton call a function?

Thanks,

Tom.


Nov 18 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.