简体   繁体   English

JavaScript 是/否 前面的 ASP.NET 按钮事件

[英]JavaScript Yes/No Preceding ASP.NET Button Event

Hi I'm trying to learn more JavaScript AJAX.嗨,我正在尝试了解更多 JavaScript AJAX。 Basically I would like to have a popup Yes No on a delete button that would precede the actual C# event being fired.基本上,我希望在实际 C# 事件被触发之前,在删除按钮上弹出 Yes No。 I could do this all in C# but I know doing it client side would be beneficial as it would reduce server load.我可以在 C# 中完成这一切,但我知道在客户端这样做是有益的,因为它会减少服务器负载。

I'm not sure exactly how to go about this.我不确定如何 go 关于这个。 Any ideas?有任何想法吗?

You can use the javascript function called confirm您可以使用 javascript function 调用确认

onclick="return confirm ('Are you sure you want to delete this _____?');"

This text parameter is the text that will be shown in the modal with the yes and no.此文本参数是将在模态中显示的文本,带有是和否。

The Yes returns true which allows the postback to continue, but the No returns false and will stop the postback. Yes 返回 true 允许回发继续,但 No 返回 false 并停止回发。

EDIT:编辑:

As mentioned by XaiSoft and Cybernate, if you are using an ASP.NET button you can also use the OnClientClick property which will be translated to onclick by the server.正如 XaiSoft 和 Cybernate 所提到的,如果您使用的是 ASP.NET 按钮,您还可以使用OnClientClick属性,该属性将由服务器转换为onclick

You can use OnClientClick property of the asp:Button .. along with the JS confirm.. Try something like the code below in your aspx/ascx/master:您可以使用asp:Button .. 的OnClientClick属性以及 JS 确认 .. 在您的 aspx/ascx/master 中尝试以下代码:

<asp:Button id="cmdSubmit" OnClientClick="return confirm('Are you sure?')" runat="server" .../>

You can also use jQuery instead of the ugly default confirm.您也可以使用 jQuery 代替丑陋的默认确认。 Here is a question addressing that. 是一个解决这个问题的问题。

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

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