gpt4 book ai didi

javascript - ASP.NET ImageButton onclick javascript 未触发

转载 作者:行者123 更新时间:2023-11-28 01:45:11 25 4
gpt4 key购买 nike

我的网站上有很多非常相似的页面,其中许多页面上都有图像按钮,可以删除或删除某种网格/树条目。对于所有这些,我想绑定(bind)一个 JavaScript,它基本上会弹出一个“你真的想删除 x”对话框窗口吗?

它几乎在每个页面上都运行良好,但在这个特定的页面上,脚本永远不会触发。检查按钮时,我看到正确列出了 onclick 事件。但是单击按钮后,我在客户端上收到以下控制台错误:

ReferenceError: removeButtonConfirmation is not defined

没有其他事情发生。

.ascx 文件中的按钮:

<telerik:GridTemplateColumn UniqueName="DeleteColumn">
<ItemTemplate>
<asp:ImageButton runat="server" ID="DeleteButton" CommandName="Delete" />
</ItemTemplate>
</telerik:GridTemplateColumn>

背后的代码:

var deleteButton = item["DeleteColumn"].FindControl("DeleteButton") as ImageButton;
deleteButton.ImageUrl = UrlHelper.SharedImage("delete2.png");
deleteButton.ToolTip = SiteTextResources.Administration_ShippingManager_Remove;
var onclickValue = String.Format("return removeButtonConfirmation('{0}');", "Are you sure you want to delete this?");
deleteButton.Attributes.Add("onclick", onclickValue);

js:

function removeButtonConfirmation(message) {
var result = window.confirm(message);
if (result)
return true;
else
return false;
}

最佳答案

不要添加 onclick 属性,而是使用 ImageButton 的 OnClientClick 属性,如下所示

将以下代码替换为行后代码

var onclickValue = String.Format("return removeButtonConfirmation('{0}');", "Are you sure you want to delete this?");
deleteButton.Attributes.Add("onclick", onclickValue);

有了这个

deleteButton.OnClientClick = String.Format("return removeButtonConfirmation('{0}');", "Are you sure you want to delete this?");

关于javascript - ASP.NET ImageButton onclick javascript 未触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20419813/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com