我如何从gridview中的ButtonField调用JS函数
本文关键字:ButtonField 调用 JS 函数 中的 gridview | 更新日期: 2023-09-27 18:12:45
我在页面顶部有一个JavaScript函数,我希望它从gridview中的ButtonField(类型:Image)调用,但我不能因为OnClick不可用。怎么做呢?
<asp:ButtonField CommandName="cmdDelete" ImageUrl="~/assets/global/images/shopping/delete.png" ButtonType="Image" ControlStyle-Width="25px" ControlStyle-Height="20px" />
功能:
function GetConfrim() {
if (confirm("Are You Sure ?")) {
return true;
} else {
return false;
}
}
事件背后按钮应该只运行,如果我按下是,否则不。
if (e.CommandName == "cmdDelete")
{
MngPropertyDetails.DeletePropertyDetails(PropertyDetailsID);
ResultLabel.ResultLabelAttributes("Record Delete Successfully!", ProjectUserControls.Enums.ResultLabel_Color.Green);
ShowPropertyDetails();
}
此代码位于RowCommand Event中
不适合ButtonField
<asp:ButtonField CommandName="cmdDelete" ImageUrl="~/assets/global/images/shopping/delete.png" ButtonType="Image" ControlStyle-Width="25px" ControlStyle-Height="20px" />
<asp:TemplateField>
<ItemTemplate>
<asp:ImageButton ID="btnDelete" runat="server" ImageUrl="~/assets/global/images/shopping/delete.png" CommandName="cmdDelete" OnClientClick="return confirm('Are you Sure ?');" Width="25" Height="20"/>
</ItemTemplate>
</asp:TemplateField>
你好,你可以简单地在OnclientClick上显示确认框,如下所示
<asp:ImageButton runat="server" ImageUrl="/xx/xx/icon-close.png" CausesValidation="false" CommandName="xxx"
CommandArgument='xxx' OnClientClick="return confirm('Are you sure you want to delete this?');" />
你应该这样做,
Button btn = (Button)e.Row.Cells[1].Controls[1];
btn.Attributes.Add("onclick","yourFunction()");