ASP.NET onclientclick C#

发布于 2024-08-04 17:08:19 字数 758 浏览 10 评论 0原文

我有一个带有 onclientclick js 函数的 ImageButton:

deleteButton = new ImageButton();
deleteButton.ID = "deleteRiskButton" + planRisk.Id;
deleteButton.ImageUrl = "../../Images/deleteButton.gif";
deleteButton.Click += new ImageClickEventHandler(deleteButton_Click);
deleteButton.OnClientClick = "removeRowAfterDeletion('" + deleteButton.ID + "')"; 

在这个 JavaScript 函数中,我有一个对话框,确保用户打算删除有问题的项目。

function removeRowAfterDeletion(buttonId)
   {
        var deleteConfirmationDialog = confirm("Are you sure you want to remove this risk from your plan?.")
        return deleteConfirmationDialog;
   }

我的印象是,如果 onclientclick 函数返回 false,则不会发生回发。但是,即使我单击取消,deleteButton_Click c# 函数也会被调用。

知道问题是什么吗?

I have an ImageButton with an onclientclick js function attached:

deleteButton = new ImageButton();
deleteButton.ID = "deleteRiskButton" + planRisk.Id;
deleteButton.ImageUrl = "../../Images/deleteButton.gif";
deleteButton.Click += new ImageClickEventHandler(deleteButton_Click);
deleteButton.OnClientClick = "removeRowAfterDeletion('" + deleteButton.ID + "')"; 

Inside this JavaScript function i have a dialog making sure the user intended to delete the item in question.

function removeRowAfterDeletion(buttonId)
   {
        var deleteConfirmationDialog = confirm("Are you sure you want to remove this risk from your plan?.")
        return deleteConfirmationDialog;
   }

I was under the impression that if the onclientclick function returns false then the postback would not occur. However, even if the I click cancel the deleteButton_Click c# function is called.

Any idea what the problem is?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

私藏温柔 2024-08-11 17:08:19

试试这个:

deleteButton.OnClientClick = "return removeRowAfterDeletion('" + deleteButton.ClientID + "')";

try this:

deleteButton.OnClientClick = "return removeRowAfterDeletion('" + deleteButton.ClientID + "')";
维持三分热 2024-08-11 17:08:19
deleteButton.OnClientClick = "return removeRowAfterDeletion('" + deleteButton.ID + "')";

试试这个。

deleteButton.OnClientClick = "return removeRowAfterDeletion('" + deleteButton.ID + "')";

Try this.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文