How prompt user to confirm action?

I have an asp form that contains a delete button.  When the user clicks the delete button, I want to prompt the user to confirm that they really do want to delete the record.

In windows vb coding I would use the following:

Dim mResponse As String
        mResponse = MsgBox("ARE YOU SURE you want to PERMANENTLY REMOVE this record?", "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2)
        If mResponse = 7 Then
            Exit Sub
        Else
            'do delete here...
        End If


How do I do this type of confirmation in asp coding?  Would like to add it to the vb Code Behind section in the btnDelete Click event.  Here is that code:

    Protected Sub btnDelete_Click(sender As Object, e As System.EventArgs) Handles btnDelete.Click
        '(Want to put the prompt here...)

        DataSource_CWDW_Retail.DeleteCommand = "DELETE ReportRecipients WHERE RecipientEmail = '" & Trim(txtEmailAddress.Text) & "'"
        DataSource_CWDW_Retail.Delete()
        gridStoresRetailSummary.DataBind()
        gridStoresRetailSummary.SelectedIndex = -1
        srClearFields()
    End Sub

Thank you for the help
LVL 7
EYoungAsked:
Who is Participating?
 
HainKurtSr. System AnalystCommented:
just add this to your code:

btnDelete.attributes.add("onclick","return confirm('are you sure to delete this?');")
0
 
EYoungAuthor Commented:
I added that to the aspx.vb code and it did not work.  First I added it to the vb code behind as follows:

    Protected Sub btnDelete_Click(sender As Object, e As System.EventArgs) Handles btnDelete.Click
        btnDelete.Attributes.Add("onclick", "return confirm('Are you sure you want to DELETE this record?');")

        DataSource_CWDW_Retail.DeleteCommand = "DELETE ReportRecipients WHERE RecipientEmail = '" & Trim(txtEmailAddress.Text) & "'"
        DataSource_CWDW_Retail.Delete()
        gridStoresRetailSummary.DataBind()
        gridStoresRetailSummary.SelectedIndex = -1
        srClearFields()
    End Sub


Then I added it to the aspx file as follows and it generates an error:

                            <asp:Button ID="btnApply" runat="server" Text="Apply" Height="30px" Width="70px"
                                style="position:absolute; top:360px; left:120px"
                                ToolTip="Click to update or add this recipient's settings in the distribution list for this report"                                
                                btnDelete.Attributes.Add("onclick", "return confirm('Are you sure you want to DELETE this record?');") />
0
 
EYoungAuthor Commented:
Oops.  Here is the aspx file with the code added:

<asp:Button ID="btnDelete" runat="server" Text="Delete" Height="30px" Width="70px"
                                btnDelete.Attributes.Add("onclick", "return confirm('Are you sure you want to DELETE this record?');")
                                style="position:absolute; top:360px; left:220px"
                                ToolTip="Click to remove this recipient from the distribution list for this report" />

Nether seems to work.  What am I missing?

Thanks
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
ALaRivaCommented:
Put the code in the Page_Load Event.
0
 
EYoungAuthor Commented:
OK, I figured it out.  The code has to be placed in the Page_Load event.
0
 
EYoungAuthor Commented:
Thanks
0
 
EYoungAuthor Commented:
How do I change the popup's title from "Message from webpage" to "Confirmation"?  Thanks
0
 
ALaRivaCommented:
You can't. Security Concerns prevent this.

You'll have to either use a modal popup, or a third party library, etc., but natively you won't be able to do this.

- Anthony
0
 
EYoungAuthor Commented:
OK.  thanks
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.