add confirm to delete link button

Last post 06-10-2009 1:50 PM by Rick Matthys. 4 replies.

Sort Posts:

  • add confirm to delete link button

    06-10-2009, 11:50 AM
    • Member
      36 point Member
    • kldeutsch
    • Member since 04-23-2008, 6:17 PM
    • St. Paul, MN
    • Posts 234

    I have a link button on my aspx page in 1.1 that allows a user to delete a row, but i need to put in a confirmation, I tried a javascript version, but it shows the popup but still deletes the record, how can I change this to work correctly.

    Private Sub myDataGrid_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles myDataGrid.ItemCommand
            Dim MobId As String = e.Item.Cells(0).Text

            If (e.CommandName = "Delete") Then
                RegisterClientScriptBlock("showMessage", "<script language=""JavaScript""> confirm('This will delete this UIC and all associated Records.'); </script>")

                sql = "Delete from tblUnitDeployData where intUnitMobId = " & MobId & " go Delete from tblUnitPostion where intUnitMobId = " & MobId "

            End If
            insertUpdateDelete(sql)
            DatagridFill()
        End Sub

  • Re: add confirm to delete link button

    06-10-2009, 1:01 PM
    Answer

    http://davidhayden.com/blog/dave/archive/2004/04/01/198.aspx

    Give a man a fish and you feed him for a day. Teach a man to fish and you feed him forever.
  • Re: add confirm to delete link button

    06-10-2009, 1:11 PM
    Answer
    • Member
      106 point Member
    • X-treme
    • Member since 01-05-2008, 8:39 AM
    • India
    • Posts 42

    Hi,

     

    I am posting a sample code. Please go through it.

    <asp:LinkButton id="LinkButton1" runat="server" Text="Delete" CausesValidation="False" CommandName="Delete" OnClientClick="return confirm('Are you sure to delete?')"></asp:LinkButton>  

    тнαηкѕ ιη α∂ναη¢є,
    χ-тяємє.....
    Software Developer
    Filed under:
  • Re: add confirm to delete link button

    06-10-2009, 1:49 PM
    • Member
      36 point Member
    • kldeutsch
    • Member since 04-23-2008, 6:17 PM
    • St. Paul, MN
    • Posts 234

    Still using ASP.net 1.1  don't have access to the onClientClick command that 2005 and up have.

  • Re: add confirm to delete link button

    06-10-2009, 1:50 PM
    Answer
    • Contributor
      2,369 point Contributor
    • Rick Matthys
    • Member since 01-20-2009, 10:57 AM
    • Oregon
    • Posts 336

    Just add this in your page load (or vb equivalent)

    string msg = "Construct some question to ask the user";
    string confirmMsg = "javascript:return confirm('" + msg + "')";
    yourLinkButton.Attributes["onclick"] = confirmMsg;

     ~Rick

    Please mark the post as ANSWER if it helps you

    Disclaimer: Just my opinion. Not my employer or anyone else....
Page 1 of 1 (5 items)