Home > DeveloperSection > Forums > asp:ImageButton click using javascript not working UI
Chintoo Semi

Total Post:135

Points:947
Posted on    June-02-2015 7:37 AM

 ASP.Net C#  JavaScript 
Ratings:


 1 Reply(s)
 499  View(s)
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.



Kamlakar Singh
Kamlakar Singh

Total Post:194

Points:1396
Posted on    June-02-2015 8:03 AM

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)


Don't want to miss updates? Please click the below button!

Follow MindStick