为什么即使在此处的 asp.net LinkButton 中返回 false 也无法停止回发?
我有一个 LinkButton,我想在确认时停止回发。
但问题是,即使我在确认时单击“取消”,它仍然会回发。
我如何将它绑定到确认函数是这样的:
LinkButton lbtn = e.Row.FindControl("btnDelete") as LinkButton;
lbtn.CommandArgument = e.Row.RowIndex.ToString();
const string js = @"confirmDelete(this,{0})";
lbtn.Attributes["onClick"] = string.Format(js, e.Row.RowIndex);
这就是函数:
function confirmDelete(lbtn, rowIndex) {
var tr = $(lbtn).closest('tr');
var formalColor= tr.css('background');
tr.css('background', '#FF0000');
var retVal = confirm("Are you sure you want to delete?");
tr.css('background', formalColor);
alert(retVal);
return retVal;
};
那么如果用户单击取消,我应该做什么来防止回发 - 这是链接按钮的特殊情况吗?
I have one LinkButton that I want to stop post-back on confirmation.
But the problem is even I click CANCEL on confirmation, it still post-backs.
How I bind it to confirmation func is like this:
LinkButton lbtn = e.Row.FindControl("btnDelete") as LinkButton;
lbtn.CommandArgument = e.Row.RowIndex.ToString();
const string js = @"confirmDelete(this,{0})";
lbtn.Attributes["onClick"] = string.Format(js, e.Row.RowIndex);
And this is the function:
function confirmDelete(lbtn, rowIndex) {
var tr = $(lbtn).closest('tr');
var formalColor= tr.css('background');
tr.css('background', '#FF0000');
var retVal = confirm("Are you sure you want to delete?");
tr.css('background', formalColor);
alert(retVal);
return retVal;
};
So what should I do to prevent post-back if the user clicks CANCEL -is it a special case for Linkbuttons?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试使用
Try to use
...如果函数返回 false,将取消事件。
...will cancel the event if the function returns false.