ASP:IMAGEBUTTON CLICK USING JAVASCRIPT NOT WORKING UI

Chintoo Semi

Total Post:135

Points:947
Posted by  Chintoo Semi
 1031  View(s)
Ratings:
Rate this:
<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.

  1. Kamlakar Singh

    Post:194

    Points:1396
    Re: asp:ImageButton click using javascript not working UI

    You'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)

      Modified On Apr-09-2018 11:49:15 PM

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!