Note that there are some explanatory texts on larger screens.

plurals
  1. POASP.NET GridView ItemTemplate LinkButton Support for RowCommand AFTER JavaScript Confirmation
    primarykey
    data
    text
    <p>Given the following GridView code:</p> <pre><code>&lt;asp:GridView ID="gvReq" runat="server" DataSourceID="objdsReq" &gt; &lt;Columns&gt; &lt;asp:TemplateField HeaderText="Control"&gt; &lt;ItemTemplate&gt; &lt;asp:LinkButton ID="lbdelete" runat="server" CommandArgument='&lt;%# Container.DataItemIndex %&gt;' ForeColor="Red" CommandName="DeleteReq"&gt;Delete&lt;/asp:LinkButton&gt; &lt;/ItemTemplate&gt; &lt;/asp:TemplateField&gt; &lt;/Columns&gt; &lt;/asp:GridView&gt; &lt;asp:ObjectDataSource ID="objdsReq" runat="server" SelectMethod="GetDataTable" &gt; &lt;%-- parameter list --%&gt; &lt;/asp:ObjectDataSource&gt; </code></pre> <p>In the RowDataBound event, JavaScript code is added:</p> <pre><code>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}") </code></pre> <p>The JavaScript fires, but the RowCommand event will never fire - I'm guessing because it is only handled by the JavaScript:</p> <pre><code>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 </code></pre> <p>The JavaScript confirmation dialog was put there by requirement by Management.</p> <p>Now, how do I get the RowCommand Event Handler to fire if someone clicks <code>OK</code> to the JavaScript confirm box? </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload