I’m busy creating a page and noticed strange behaviour of a button inside a grid-view cell that needs to invoke the GridView.RowCommand event of the grid-view.
When I set the OnClientClick="" instead of “OnClientClick=”javascript:DoMethod()”theRowCommand` does not fire. The function can contain nothing as I’ve also noticed that any script inside the method does not get executed.
Can someone please explain to me why this is happening? Am I doing something wrong? I’ve Googled this extensively and cannot find an explanation.
Thanks in advance for solutions and suggestions.
Regards
For more detailed code and reference to previous questions regarding this page see Button Click event not firing and JavaScript Object Expected Error
The Code:
function addAcc(a,b) {
var btn = document.getElementById(a);
};
<asp:Button ID="btnAddAcc" runat="server" Text="Add Account"
OnClientClick="javascript:addAcc(this.id,<%# CType(Container, GridViewRow).RowIndex %>)" />
Maybe the answer to this question is exactly what you are looking for: Event not firing after setting OnClientClick in RowDataBound