从 javascript 调用 OnCheckedChanged 事件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21905663/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Call OnCheckedChanged event from javascript
提问by oteal
when user change the checkbox, I want first show my custom confirm dialog message. If user select yes, I want fire the code behing event processado_CheckedChanged(object sender, EventArgs e)
当用户更改复选框时,我想首先显示我的自定义确认对话框消息。如果用户选择是,我想触发代码behing event processado_CheckedChanged(object sender, EventArgs e)
I tried something like:
我试过类似的东西:
<asp:CheckBox ID="processado" runat="server" OnCheckedChanged="javascript:confirmingChange();" AutoPostBack="true" />
<asp:CheckBox ID="processado" runat="server" OnCheckedChanged="javascript:confirmingChange();" AutoPostBack="true" />
And my js:
还有我的js:
function confirmingChange() {
$.confirm({
'title': 'Confirm',
'message': 'Are you sure?',
'buttons': {
'Yes': {
'action': function () {
__doPostBack(document.getElementById('processado'), '');
}
},
'No': {
'action': function () {
return false;
}
}
}
});
return false;
}
How can I fire my codebehind event using javascript? Thanks.
如何使用 javascript 触发我的代码隐藏事件?谢谢。
回答by Adil
You need onchange instead of OnCheckedChanged and return true if you want postback and false otherwise.
您需要 onchange 而不是 OnCheckedChanged 并且如果您想要回发则返回 true 否则返回 false 。
<asp:CheckBox ID="processado" runat="server" onchange="return javascript:confirmingChange();"
OnCheckedChanged="ServerSideEventHandlerHere" AutoPostBack="true" />
回答by Juhi
For calling javascript you have to use "onchange" and you have to use "return".
要调用 javascript,您必须使用“ onchange”并且您必须使用“ return”。
onchange="return javascript:confirmingChange(); "
onchange="返回 javascript:confirmingChange();"