Given the following GridView code:
<asp:GridView ID="gvReq" runat="server" DataSourceID="objdsReq" >
<Columns>
<asp:TemplateField HeaderText="Control">
<ItemTemplate>
<asp:LinkButton ID="lbdelete" runat="server" CommandArgument='<%# Container.DataItemIndex %>' ForeColor="Red" CommandName="DeleteReq">Delete</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:ObjectDataSource ID="objdsReq" runat="server" SelectMethod="GetDataTable" >
<%-- parameter list --%>
</asp:ObjectDataSource>
In the RowDataBound event, JavaScript code is added:
Protected Sub gvReq_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gvReq.RowDataBound
If (e.Row.RowType = DataControlRowType.DataRow) Then
Dim lbdelete As LinkButton = e.Row.Cells(DELETE_CELL).Controls.Item(1)
lbdelete.Attributes.Add("onclick", "javascript:if(confirm('Are you sure you want to delete?')){return true}else{return false}")
The JavaScript fires, but the RowCommand event will never fire - I'm guessing because it is only handled by the JavaScript:
Protected Sub gvReq_RowCommand(ByVal sender As Object, ByVal e As GridViewCommandEventArgs) Handles gvReq.RowCommand
Dim dataItemIndex As Integer = Convert.ToInt32(e.CommandArgument)
Dim reqID As Integer = Convert.ToInt32(gvReq.DataKeys(dataItemIndex).Values(0))
If e.CommandName = "DeleteReq" Then
The JavaScript confirmation dialog was put there by requirement by Management.
Now, how do I get the RowCommand Event Handler to fire if someone clicks OK
to the JavaScript confirm box?