So I have a javascript function:
function confirmDeleteContact() {
if (confirm("Are you sure you want to delete this contact?")) {
document.all.answer.value="yes";
} else {
document.all.answer.value="no";
}
}
and I wire it to a grid item like so:
Sub dgbind(ByVal sender As Object, ByVal e As DataGridItemEventArgs) Handles dgcontacts.ItemDataBound
Select Case e.Item.ItemType
Case ListItemType.Item, ListItemType.AlternatingItem
CType(e.Item.Cells(9).Controls(0), System.Web.UI.WebControls.LinkButton).Attributes.Add("onclick", "javascript:confirmDeleteContact();")
End Select
End Sub
This is some old code, so I see a few things I could change up, but the moral is this: If all else fails, add the javascript "onClick" during row binding. "document.all.answer.value" is a hidden field that has runat=server
so that I can read the value upon postback.