ASP.NET 3.5 / AJAX - ImageButton_Click is undefined


Having just deployed my first website in ASP.NET with use of the Ajax Library I have recently been informed of an error message in IE 7 where I am using an ASP:ImageButton (it works in Firefox and Chrome).

The error message is 'ImageButton1_Click' is undefined. There are probably about 6 or 7 ImageButtons in the whole project and each time I get the same error message but with a different object name.

Having tried ASP:Buttons and ASP:LinkButtons neither of these work too.

I have researched and googled as much as I possiblity can with no solutions. I hate to admit defeat so please can an expert help?

Many thanks in advance.

PS - The "code behind" the button is  
<form runat="server">
<asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="~/images/design/button_green_confirm.png" OnClientClick="ImageButton1_Click" /></form>

Partial Class index
    Inherits System.Web.UI.Page

    Protected Sub ImageButton1_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles ImageButton1.Click
        Dim strIsThisDoingMyNut As String
        strIsThisDoingMyNut = "Hell Yes!"
    End Sub
End Class

Open in new window

Who is Participating?
You have OnClientClick="ImageButton1_Click"
so it is expecting a javascript method on Client side...

If you want to just use serverside method that you have above in your code then remove that part: OnClientClick="ImageButton1_Click" it is not necessary.
David RobitailleAnalyst ProgrammerCommented:
or use OnClick="ImageButton1_Click" ...
advfinanceAuthor Commented:
And that's why they call you a genius!

Thanks buddy - I didn't even consider that ClientClick would mean a client side operation (may come in very handy someday). You learn something new ever day!

Cheers :o)
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

advfinanceAuthor Commented:
--> or use OnClick="ImageButton1_Click" .

No that is not required "Handles ImageButton1.Click" should take care of that ....

Adding that might cause button click to fire twice ....depending on AutoEventWireup property...
David RobitailleAnalyst ProgrammerCommented:
guru_sami, you are right. it`s either a handle or a onClick, not both.
 I just wanted to mention that the property to use when you want to set a sub to handle the click event from the aspx code is OnClick, not onClientClick.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.