I have a gridview in ASP.net 2.0 that has a small peace of javascript code that when you click the row, it will be selected.
cell.Attributes.Add("onClick", Page.ClientScript.GetPostBackClientHyperlink(this, "Select$" + row.RowIndex.ToString()));
This code works perfect, but when I have a link or button in a gridview row and as soon as that will be clicked, a postback will occur and override the link or button action.
My question, knows anybody a solution to cancel the row javascript onclick event?
The following solutions I have unsuccessfully tested:
return false;- jQuery with
event.stopImmediatePropagationworks, but I use pagination so the event doesn’t bound to the new page. - jQuery with
.live("click", function(){...});works with pagination, but theevent.stopImmediatePropagationisn’t supported inliveanddelegate.
Ok, I found the following solution:
Place this in the control in the gridview:
And this in the page/head: