asp:ImageButton not firing onclick event

cdonner picture cdonner · Apr 25, 2009 · Viewed 51.1k times · Source

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

Answer

Atanas Korchev picture Atanas Korchev · Apr 25, 2009

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).