开发者

How to ask the user for confirmation of an action with a popup box?

开发者 https://www.devze.com 2022-12-11 23:55 出处:网络
I\'m currently coding a button which will delete a record from a database if clicked. However, I want some sort of confirmation after they click it so there are no accidents. I was imagining a popup b

I'm currently coding a button which will delete a record from a database if clicked. However, I want some sort of confirmation after they click it so there are no accidents. I was imagining a popup box that tells them they are about to d开发者_运维问答elete this record with two buttons cancel and OK. If cancelled, nothing happens, but if OK is pressed, then the server would execute the delete as coded. How would I do this in asp/vb?


Here is a button with a confirmation message :

<asp:Button runat="server" ID="btnDelete" 
     OnClick="btnDelete_Click" 
     OnClientClick="return confirm('Do you want to delete the record ? ');" />

Here is the way to add confirm client script at server side :

btnDelete.Attributes.Add("onclick", 
        "return confirm('Do you want to delete the record ? ');")


Adding Client-Side Message Boxes in your ASP.NET Web Pages is a great tutorial to make client-side confirmation messages like this:

How to ask the user for confirmation of an action with a popup box?

Using ASP.NET & VB.NET (Don't forget to read part2.)

0

精彩评论

暂无评论...
验证码 换一张
取 消