Alex Rivera | Logout

asp:ImageButton not firing onclick event

Asked 2009-04-25T01:18:51.033
10

I have a page that uses a master page, several RequiredFieldValidators, and the Web Toolkit autocomplete extender. The following code only shows the bare minimum of the page:

<%@ Page Language="C#" 
    AutoEventWireup="true"  
    CodeFile="Login.aspx.cs" 
    MasterPageFile="~/master.master" 
    Inherits="Login" %>

<asp:Content id="Content1" 
    contentplaceholderid="ContentPlaceHolder1" 
    runat="server">
    <asp:UpdatePanel ID="pnlUpdate" runat="server">
        <ContentTemplate>
            <div>
                <asp:ImageButton class="submitButton" 
                    imageurl="images/button_submit.gif" 
                    id="btnSubmit" 
                    runat="server" 
                    onclick="btnSubmit_ServerClick"/>
            </div>
        </ContentTemplate>
    </asp:UpdatePanel>
</asp:Content>

Code-behind:

protected void btnSubmit_ServerClick
      (object sender, ImageClickEventArgs e)
{
    //breakpoint here does not get hit
}

The <form runat="server"> tag is in the master page. The code above does not fire the onclick event. If I get rid of the master page and add a form tag to the page, it works. Is the form tag in the master page not supported, or is this supposed to work somehow? alt text http://digitalcopy.warnerbros.com/images/mainmenu.gif?provider=00079&disc=03403AAA-1D20-47F2-91FA-5EE632832659

Edit
Report

3 Answers

12

You can also check if your ImageButton does not trigger validation. If it does set its CausesValidation property to false (of course if it makes sense).

answered 2009-04-25T05:52:57.053
0

You can always try taking out the UpdatePanel and seeing if it works. I usually start without the UpdatePanel, get everything working the way I want and then add in the UpdatePanel and debug anything that causes.

The form in the MasterPage works for me so the ScriptManager/ScriptManagerProxy mentioned by @Keltex might be an issue, though I forget them sometimes and usually get away with it.

With the UpdatePanel the button's click event will be handled via Javascript, so you might grab FireBug or equivalent (depending on browser) and follow through what actually is happening. Is it tripping on the validation and you don't see it? Is there a JS error somewhere (the Control Toolkit isn't perfect always)? Is the page actually posting back at all and just not hitting the event handler?

answered 2009-04-25T04:01:41.113
0

I had the same problem that OnClick event of ImageButton was not firing. But the actual problem was, at form level, I had onSubmit="return false;"

answered 2013-04-04T11:59:39.697

Your Answer