asp:ImageButton not firing onclick event
Solution 1
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).
Solution 2
My solution was to set the ImageButton's CausesValidation to false.
Solution 3
I had a similar issue (different scenario). I used Page.RegisterRequiresRaiseEvent(ImageButton)
and my onclick event started to fire. Why I needed to do that? I don't know.
Solution 4
ib.ID = i + ":" + j;
should be changed to
ib.ID = i.toString()+":"+j.toString();
If it still doesn't work try making use of the StringBuilder to buildup the ID and assign it later to ib.ID property
Solution 5
This is solution that worked for me
If you are binding through data bound controls then use OnCommand attr instead of OnClick attr
cdonner
„Dem Herrn Ingeniör ist nichts zu schwör." At pod, We are aways looking for new and interesting projects.
Updated on August 23, 2020Comments
-
cdonner over 3 years
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 -
cdonner about 15 yearsThe master page also has AutoEventWireup=true, and the web.config does not override it. Bummer.
-
cdonner about 15 yearsI moved the form tag (and the script manager) out of the master page and into the content page. The event fires now, and I still have the master page. Not ideal, but enough of a workaround for now.
-
Chad Grant about 15 yearsIf you have an UpdatePanel in your master page, try removing it
-
cdonner about 15 yearsNegative - only plain HTML in the master page.
-
cdonner about 15 yearsI did strep through the JS and saw the event being processed, and no exception raised. Why it does not get send to the server was not obvious to me. I would have to dig deeper into the generated client-side code in order to understand it. Removing the UpdatePanel did not change the behavior.
-
cdonner about 15 yearsGreat point. Adding a scriptmanagerproxy did not help though. I put the form back on the master, and kept the scriptmanager on the content page, which also did not work. It only works if the both the form and the scriptmanager tags are on the content page. Weird.
-
cdonner about 15 yearsIt does trigger validation, because it works fine with the workaround in place.
-
skvyas about 15 yearsWhat happens if you swap a normal button for the image button? Does it work? Does it behave the same in all browsers?
-
skvyas about 15 yearsReading your comment more closely it sounds like a validator/JS issue, since it's not making it back to the server. Do you have any other controls like Control Toolkit controls that could interfere with the Image Button?
-
JsonStatham over 9 yearsThanks this was blocking my event firing too