简体   繁体   English

如何要求用户通过弹出框确认操作?

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

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 delete 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. 如果取消,则什么也不会发生,但是如果按OK,则服务器将按编码执行删除。 How would I do this in asp/vb? 我将如何在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: 在ASP.NET网页中添加客户端消息框是制作这样的客户端确认消息的绝妙教程:

替代文字

Using ASP.NET & VB.NET (Don't forget to read part2.) 使用ASP.NET和VB.NET(不要忘记阅读part2。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM