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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

HainKurtSr. System AnalystCommented:
just add this to your code:

btnDelete.attributes.add("onclick","return confirm('are you sure to delete this?');")
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
Angular Fundamentals

Learn the fundamentals of Angular 2, a JavaScript framework for developing dynamic single page applications.

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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.