使用 JavaScript 在 ASP.NET 中显示确认框
我需要显示确认框“您确定要继续吗?”如果“是”,我需要清除 ASP.NET 文本框值。否则不应清除。
I need to show the confirm box "Are you sure You Want To continue?" If "Yes" I need the ASP.NET textbox value to be cleared out. Otherwise it should not be cleared.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
在您的 asp 文本框标记中添加以下内容:
...
并添加此脚本:
如果您希望在单击单选框时发生这种情况,请将其放入此标记中,然后将 onclientclick 替换为 onclick。
In your asp textbox tag add this:
...
And add this script:
If you want this to happen on click of your radio box, put it in this tag and just replace onclientclick with onclick.
注意 myAspTextBox 指的是 asp:textbox 控件 ID 属性的名称
希望这有帮助
Note the myAspTextBox refers to the name of the asp:textbox controls ID property
Hope this helps
如果您下载AjaxControlToolkit,您可以使用ConfirmButtonExtender在按钮后向用户显示一个简单的确认框单击可继续操作或取消
您可以在此处查看 获取示例,此处获取有关如何实现此功能的教程
好吧,我刚刚注意到了这一点关于单选按钮,无论如何,如果您想在 .Net 项目中实现 JavaScript 解决方案,AjaxControlToolkit 都是一个不错的起点
If you download the AjaxControlToolkit you can use the ConfirmButtonExtender to display a simple confirmation box to a user after a button is clicked to proceed with the action or cancel
You can see here for an example and here for a tutorial on how to implement this
Okay I just noticed the bit about radio buttons, in any case the AjaxControlToolkit is a good place to start if you want to implement JavaScript solutions in .Net projects
如果这是您的文本框标记:
然后这是将触发确认的按钮:
那么您将需要以下 javascript:
如果您只想清除文本框但始终继续回发,那么您不需要曾经需要像上面一样返回 false,但总是像下面一样返回 true。在这种情况下,您应该重新考虑向用户显示的消息。
if this is your textbox markup:
and then this is the button that will trigger the confirm:
then you'll need the following javascript:
If all you want to do is to clear the textbox but always continue with the postback then you don't ever need to return false as above but always return true as below. In this scenario you should rethink the message you display to the user.
函数中还有一个定时器停止做的事情。如果按“确定”,确认框计时器将停止,并且它会重定向到新页面“Default2.aspx”,
否则如果选择取消,则不会发生任何情况。
There is also a timer stop doing in the function. The confirmation box if press "Ok" timer stops and also its redirected to new page "Default2.aspx"
else if chosen cancel then nothing happens.