Javascript 当DevExpress ASPxCheckBox发生更改时,请求客户端确认
我正在尝试添加一个确认对话框,让用户确认对ASPxCheckBox的选中状态所做的更改 取1Javascript 当DevExpress ASPxCheckBox发生更改时,请求客户端确认,javascript,checkbox,devexpress,Javascript,Checkbox,Devexpress,我正在尝试添加一个确认对话框,让用户确认对ASPxCheckBox的选中状态所做的更改 取1 基于此,我正在尝试以下代码: 使用此JavaScript: function ConfirmChange (s, e) { console.log(s); console.log(e); return false; // For testing // return confirm(); // Should become this } function Confirm
基于此,我正在尝试以下代码:
使用此JavaScript:
function ConfirmChange (s, e) {
console.log(s);
console.log(e);
return false; // For testing
// return confirm(); // Should become this
}
function ConfirmChange (s, e) {
e.isValid = confirm();
}
function ConfirmChange (s, e) {
console.log(s);
console.log(e);
//Save the checked state
value = s.GetChecked();
//Revert changes immediately
s.SetChecked(!s.GetChecked());
result = false; // For testing
// result = confirm(); // Should become this
if (result) {s.SetChecked(value);}
}
我希望/期望返回false
位来阻止更改,但它还是发生了。我已经检查了控制台记录的参数,看看我是否可以影响那里的任何东西,但看起来不像。我也读过这本书,但它也不知道我的目的
第二次拍摄我也尝试过在代码隐藏中这样做:
var checkbox = (ASPxCheckBox)myGridView.FindEditRowCellTemplateControl(myCol, "ASPxCheckBox1";
checkbox.Attributes.Add("onclick", "return confirm('You sure?')")
这还会弹出确认对话框,如果单击取消,该对话框将无法阻止更改
取3个最后,根据早期答案中的一个建议,我还尝试了验证路线:
JavaScript:
function ConfirmChange (s, e) {
console.log(s);
console.log(e);
return false; // For testing
// return confirm(); // Should become this
}
function ConfirmChange (s, e) {
e.isValid = confirm();
}
function ConfirmChange (s, e) {
console.log(s);
console.log(e);
//Save the checked state
value = s.GetChecked();
//Revert changes immediately
s.SetChecked(!s.GetChecked());
result = false; // For testing
// result = confirm(); // Should become this
if (result) {s.SetChecked(value);}
}
但是,这不会阻止或恢复更改,但如果在“确认”对话框中单击“取消”,则会出现验证错误
所以,底线是
如何在
ASPxCheckBox
的更改发生之前插入客户端确认对话框?您无法阻止ASPxClientCheckBox.CheckedChanged
事件中的更改,因为当编辑器的选中状态更改时,此事件发生在客户端。您可以使用方法和方法还原值。下面是一个例子:
<dx:ASPxCheckBox ID="ASPxCheckBox1" runat="server">
<ClientSideEvents CheckedChanged="ConfirmChange" />
</dx:ASPxCheckBox>
就快到了。但是,它不会阻止或恢复选中状态的更改,而是在我按“取消”时在复选框旁边显示一个验证错误“(!)无效值”。@Jeroen我找到了另一种方法,使用
GetChecked
和SetChecked
方法。我已经更新了我的答案。令人遗憾的是,它确实在视觉上恢复了已检查状态,而不是(我更喜欢的)阻止更改,但我想使用DevExpress,您没有必要在意这些细节。再次感谢@杰伦:我已经更新了我的答案。您可以尝试保存选中状态,立即还原更改,从用户处获得确认并更新选中状态。哇!我想你确实很奢侈,你只需要知道要跳过哪些障碍。如果可以的话,我会再加一个+1:)