Javascript 根据JS MessageBox是/否选择执行OnServerClick
我将引导与ASP.Net一起使用 我正在尝试将确认添加到按钮中,以便只有在显示警报消息框后单击“是”时,才会执行代码隐藏。Javascript 根据JS MessageBox是/否选择执行OnServerClick,javascript,c#,jquery,asp.net,twitter-bootstrap,Javascript,C#,Jquery,Asp.net,Twitter Bootstrap,我将引导与ASP.Net一起使用 我正在尝试将确认添加到按钮中,以便只有在显示警报消息框后单击“是”时,才会执行代码隐藏。 <link href="_JS/jquery.modal.css" type="text/css" rel="stylesheet" /> <link href="_JS/jquery.modal.theme-xenon.css" type="text/css" rel="stylesheet" /> <link href="_JS/jquer
<link href="_JS/jquery.modal.css" type="text/css" rel="stylesheet" />
<link href="_JS/jquery.modal.theme-xenon.css" type="text/css" rel="stylesheet" />
<link href="_JS/jquery.modal.theme-atlant.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="_JS/jquery.modal.min.js"></script>
<!--......-->
<a href="#" runat="server" id="confirm" onserverclick="confirm_ServerClick1">Confirm</a>
<!--......-->
<script type="text/javascript">
$(document).ready(function (e) {
$('a#confirm').click(function () {
modal({
type: 'confirm',
title: 'Confirm',
text: 'Are you sure you want to remove the user from the company?',
if (result) {
//Proceeds to activate event in code behind - confirm_ServerClick1
} else {
BootstrapDialog.closeAll();
}}
});
});
});
</script>
$(文档).ready(函数(e){
$('a#confirm')。单击(函数(){
模态({
键入:“确认”,
标题:“确认”,
text:“确实要从公司中删除该用户吗?”,
如果(结果){
//继续激活代码隐藏中的事件-确认\u服务器单击1
}否则{
BootstrapDialog.closeAll();
}}
});
});
});
可能吗?如果是这样的话,我会很感激任何提示
到目前为止,它只是执行confirm_ServerClick1事件,忽略JS函数,而不显示任何模式弹出窗口。您需要在JS函数中返回true或false。False停止执行,true继续执行服务器
$('#confirm').click( function() { your_code_here; return false; // or true. the result from your popup } );
$(document).ready(function (e) {
$('a#confirm').click(function () {
modal({
type: 'confirm',
title: 'Confirm',
text: 'Are you sure you want to remove the user from the company?',
if (result) {
//your logic here
return true;
} else {
BootstrapDialog.closeAll(); return false;
}}
});
});
});
编辑
请参阅下面的示例以了解默认的JS确认。(JS确认将阻止执行,直到收到对话框的结果)。在您的情况下,引导弹出窗口不会阻止执行,您需要根据从弹出窗口收到的结果从JS调用服务器端事件。
如果结果为true,则调用类似下面的服务器端方法document.getElementById(“CliendId”)。单击()
或使用
<a href="#" runat="server" id="confirm" onclick="return confirmEvent();" onserverclick="confirm_ServerClick1">Confirm</a>
<!--......-->
<script type="text/javascript">
function confirmEvent()
{
if(confirm("Are you sure?"))
{
alert("This will execute server side event");
return true;
}
else
{
alert("I'm not sure!");
return false;
}
}
</script>
函数确认函数()
{
如果(确认(“你确定吗?”)
{
警报(“这将执行服务器端事件”);
返回true;
}
其他的
{
警惕(“我不确定!”);
返回false;
}
}
非常感谢。作为一个简单的消息框非常有用,但是,我需要做什么来添加模态syling呢?我主要做后端服务器的工作,我的JS知识非常有限。没问题,伙计。我不明白你的问题。如果您询问设置默认确认对话框的样式,则不可以。请参阅“编辑”部分。请参阅此部分。或