user1951007
user1951007

Reputation: 233

image button onclick event not fired

I have created a HTML Image button in a web application with an onclick event handler. But the event is not firing. I am using the code below to create a button and its onclick event handler.

<input type="image" runat="server" src="Plan_search/images/buy.png" onclick="goto_click" />
 protected void goto_click(object sender, EventArgs e)
 {
            try
            {

            }
            catch(Exception e1)
            {
                throw;
            }
  }

Upvotes: 2

Views: 5905

Answers (5)

coder
coder

Reputation: 2000

This is working code.Use this..

<input type="image" runat="server" src="Plan_search/images/buy.png"  onserverclick="goto_click" />

protected void goto_click(object sender, EventArgs e)
{
        try
        {

        }
        catch(Exception e1)
        {
            throw;
        }
 }

Upvotes: 2

शेखर
शेखर

Reputation: 17614

As @samjudson suggested.
It should be

  <input id="Image1" type="image" runat="server" onserverclick="goto_click" />

But I think it should be using ImageButton rather than image

Upvotes: 0

samjudson
samjudson

Reputation: 56853

I suspect you want to use the OnServerClick attribute, rather than OnClick.

Upvotes: 2

algreat
algreat

Reputation: 9002

You shouldn't create your button like input element. Create your button like ASP.NET control:

<asp:ImageButton id="imagebutton1" runat="server"          
           ImageUrl="Plan_search/images/buy.png"
           OnClick="goto_click"/>

Upvotes: 0

Clyde
Clyde

Reputation: 7549

You need parentheses:

goto_click()

And probably some arguments too.

Upvotes: -2

Related Questions