带有“是"和“否"的消息框,不带按钮 [英] Message box with yes and no without press button

查看:59
本文介绍了带有“是"和“否"的消息框,不带按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好

我在C#2010中使用ASP,我想在代码后面运行确认框,而无需按任何按钮,例如:

Hello all

i am using asp with C# 2010, i want to run confirm box behind the code without press any button for example:

bool shouldConfirm = true;
if (shouldConfirm)
    ShowConfirmBox(); //here should show confirm box, otherwise no need to show confirm box


如果是,则确认框应显示为是"和否"选项,是"将执行某些操作,而否"将执行其他操作.

你能帮我吗


谢谢大家


In case of yes the confirm box should display with yes and no option, yes will do something and no will do something else.

can you help me please


thank you all

推荐答案

对,首先,我不会使用OnClientClick来执行此操作,而是使用jQuery并使用click事件来触发此操作反而.这意味着您将具有一些类似于以下内容的代码:
Right, first of all, I wouldn''t use OnClientClick to do this, rather I would use jQuery and use the click event to trigger this instead. This means you would have some code that looks like this:


(" #ID_OF_BUTTON").单击(如果(应确认) ShowConfirmBox(); });
("#ID_OF_BUTTON").click(function() { shouldConfirm = GetMyCondition(); if (shouldConfirm) ShowConfirmBox(); });

显然,您需要在此处添加按钮的客户端ID,但这是设置点击处理程序的基本流程.

Obviously, you would need to add the client ID of your button here, but that''s the basic flow for setting the click handler.


您可以使用像这样在JS中确认框

var ans = Confirm(``记录已存在.要继续吗?'');
if(ans == true)
{
}
其他
{
}
其次,要获取代码后的响应,您可以将Yes/No值存储到隐藏字段中,例如

document.getElementById(''<%= hiddenField.ClientID%>'').value = ans;
You can use confirm box in JS like this

var ans = confirm (''Record already exist.Do you want to proceed?'');
if(ans==true)
{
}
else
{
}
Secondly, to get the response in code behind, you can store the Yes/No value into a hidden field e.g.

document.getElementById(''<%= hiddenField.ClientID %>'').value = ans;


这篇关于带有“是"和“否"的消息框,不带按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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