Note that there are some explanatory texts on larger screens.

plurals
  1. POOnClientClick doesn't fire on first postback but will on second click
    primarykey
    data
    text
    <p>Okay I have a gridview that allows users to delete a row, when the use clicks the delete link button the postback occurs. I get the index of the row that the button fires on which then calls a stored procedure that gets a count. But before the row is deleted a confirmation will display. The problem is the user has to click the Delete link button twice before the confirmation dialog box appears. Thank you in advance for your help code is below.</p> <pre><code>&lt;asp:GridView ID="updtCompGrdVw" runat="server" AutoGenerateColumns="False" DataKeyNames = "GUID" OnRowCancelingEdit="updtCompGrdVw_RowCancelingEdit" OnRowEditing="updtCompGrdVw_RowEditing" OnRowUpdating="updtCompGrdVw_RowUpdating" OnRowDeleting="updtCompGrdVw_RowDeleting" &lt;RowStyle BackColor="White" /&gt; &lt;EmptyDataRowStyle Wrap="False" /&gt; &lt;Columns&gt; &lt;asp:CommandField ShowDeleteButton="true" HeaderText="Delete" CausesValidation="false"&gt; &lt;HeaderStyle ForeColor="White" /&gt; &lt;ItemStyle HorizontalAlign="left" VerticalAlign="Top" Width="40px" Font-Bold="True" Font-Size="Small"/&gt; &lt;/asp:CommandField&gt; &lt;/Columns&gt; &lt;/asp:GridView&gt; protected void updtCompGrdVw_RowDeleting(Object sender, GridViewDeleteEventArgs e) { try { int index = Convert.ToInt32(e.RowIndex); DataKey dtKey = updtCompGrdVw.DataKeys[index]; string DKpif_id = dtKey.Values["GUID"].ToString();// +", " + dtKey.Values["itmID"].ToString(); GridViewRow Row = updtCompGrdVw.Rows[index]; conn.Close(); SqlCommand cmd3 = new SqlCommand("StoreProcedureName", conn); cmd3.CommandType = CommandType.StoredProcedure; cmd3.Parameters.Add("@GUID", SqlDbType.NVarChar); cmd3.Parameters["@GUID"].Value = DKpif_id; conn.Open(); SqlDataAdapter adapter = new SqlDataAdapter(); DataSet ds = new DataSet(); adapter.SelectCommand = cmd3; adapter.Fill(ds); if (ds.Tables.Count &gt; 0) { Session["CntctCount"] = ds.Tables[0].Rows[0]["ContactsCount"].ToString(); (Row.Cells[Row.Cells.Count - 1].Controls[0] as LinkButton).OnClientClick = "if (!confirm('There are (" + Session["CntctCount"].ToString() + ") contacts associated with this company!, Are you sure you want to Delete this company?')) { return false; }"; ds.Clear(); conn.Close(); } } catch (SqlException ex) { } } </code></pre>
    singulars
    1. This table or related slice is empty.
    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.
    1. This table or related slice is empty.
    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