<asp:ImageButton ID="btnAdd"runat="server" AlternateText="AddNew"
ImageUrl="../images/add.png" CausesValidation="true" OnClick="btnAdd_Click" />
<asp:Image ID="imgProceed" ImageUrl="~/Images/proceed.gif" runat="server"/>
Code Behind
btnAdd.Attributes.Add("onclick", "return false;"); //Adding client event to avoid submit for some validation purpose
imgProceed.Attributes.Add("onclick", "proceed('" + btnAdd.ClientID + "')");
JavaScript
function proceed(buttonId)
{ document.getElementById('<%=btnAdd.ClientID%>').removeAttribute("onclick");
document.getElementById('<%=btnAdd.ClientID%>').click();
}
I tried with the above code. I want to click the ImageButton
through JavaScript. But it is not working. I want to fire server side "btnAdd_Click"
event by clicking image button.
Anonymous User
02-Jun-2015You're setting it up to call a javascript method called proceed
imgProceed.Attributes.Add("onclick", "proceed('" + btnAdd.ClientID + "')");
but your javascript method is actually called proceedToAdd
function proceedToAdd(buttonId)