Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

asp:ImageButton not firing onclick event

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

like image 787
cdonner Avatar asked Apr 25 '09 01:04

cdonner


People also ask

Why imagebutton1_click event is not working?

Because putting the PostBackUrl property and onclick event will not work simultaneously. So, check it carefully, put a debugger on Page_Load and on that ImageButton1_Click event. Check whether it is going to Page_Load or not and then to ImageButton1_Click event. Let me know what are the findings and what is the next problem. One more thing.

Why doesn't the event fire when I type special characters?

At runtime, if you look at the HTML source of the page, you will see the special characters are either ignored or replaced with " _ ". So the page is unable to find the correct control, thus the event won't fire.

Why the event won't fire?

At runtime, if you look at the HTML source of the page, you will see the special characters are either ignored or replaced with " _ ". So the page is unable to find the correct control, thus the event won't fire. Try changing the name with plain text, the event will fire. Show activity on this post.

How to handle button click event in UpdatePanel?

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?


1 Answers

My solution was to set the ImageButton's CausesValidation to false.

like image 90
plains5728 Avatar answered Sep 21 '22 22:09

plains5728