单击复选框时如何显示确认消息 [英] How to display confirmation message when a checkbox is clicked

查看:236
本文介绍了单击复选框时如何显示确认消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello Everyone,



我希望能够在点击asp.net复选框时显示确认消息,我尝试使用:

 OnClientClick =  返回确认('您确定要标记注册吗?') 

aspx代码:

< asp:CheckBox ID =   chkSignIn  runat =   server Text =   退出 AutoPostBack =   true  OnCheckedChanged =   chkSignIn_CheckedChanged OnClientClick =   返回确认('您确定要标记注册吗?') /> 

它没有报告错误,但没有工作,我后来发现asp.net复选框没有OnClientClick属性,我也做了一些关于谷歌的研究仍然无法实现!请问有谁知道怎么做?在此先感谢。

解决方案

改为使用onclick。



 onclick =   return confirm('你确定要退出吗?') 


结合 onclick 使用 AutoPostBack 可能会很棘手。通过添加无条件的 return 语句,您最终会绕过导致页面回发到服务器的代码。



试试这个:

 <   asp:CheckBox     ID   =  chkSignIn    runat   = 服务器   文本  = 退出    AutoPostBack   =  true    OnCheckedChanged   =  chkSignIn_CheckedChanged    OnClick   =  if(!confirm('您确定'你想标记寄存器吗?'))return false;    /  >  


Hello Everyone,

I want to be able to display a confirmation message when asp.net checkbox is clicked, i tried using:

OnClientClick = "return confirm('Are you sure you want to mark register?')"

aspx code:

<asp:CheckBox ID="chkSignIn" runat="server" Text="Sign Out" AutoPostBack="true" OnCheckedChanged="chkSignIn_CheckedChanged" OnClientClick= "return confirm('Are you sure you want to mark register?')" />

it doesnt report error, but not working, i later found out that asp.net checkbox doen't have OnClientClick attribute, i have also done a few research on google still couldn't achieve! Please does anyone know how to do this? Thanks in advance.

解决方案

Use onclick instead.

onclick= "return confirm('Are you sure you want to logout?')"


Combining onclick with AutoPostBack can be tricky. By adding an unconditional return statement, you end up bypassing the code which causes the page to post back to the server.

Try this:

<asp:CheckBox ID="chkSignIn" runat="server" Text="Sign Out" AutoPostBack="true" OnCheckedChanged="chkSignIn_CheckedChanged" OnClick="if(!confirm('Are you sure you want to mark register?'))return false;" />


这篇关于单击复选框时如何显示确认消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆