[英]How do I call a JS function from ButtonField in gridview ?
I have a JavaScript function at the top of the page, I want it to call from ButtonField (type: Image) in gridview but I can't since OnClick is not available. 我在页面顶部有一个JavaScript函数,我希望它可以从gridview中的ButtonField(类型:Image)中调用,但由于OnClick不可用,所以无法使用。 How to do it ?
怎么做 ?
<asp:ButtonField CommandName="cmdDelete" ImageUrl="~/assets/global/images/shopping/delete.png" ButtonType="Image" ControlStyle-Width="25px" ControlStyle-Height="20px" />
Function: 功能:
function GetConfrim() {
if (confirm("Are You Sure ?")) {
return true;
} else {
return false;
}
}
And the event behind button should Only run if I press yes otherwise not. 并且按钮后面的事件应该仅在我按是的情况下运行,否则不运行。
if (e.CommandName == "cmdDelete")
{
MngPropertyDetails.DeletePropertyDetails(PropertyDetailsID);
ResultLabel.ResultLabelAttributes("Record Delete Successfully!", ProjectUserControls.Enums.ResultLabel_Color.Green);
ShowPropertyDetails();
}
This code is inside RowCommand Event. 这段代码在RowCommand事件内部。
that doesn't work with a ButtonField
不适用于
ButtonField
Replace 更换
<asp:ButtonField CommandName="cmdDelete" ImageUrl="~/assets/global/images/shopping/delete.png" ButtonType="Image" ControlStyle-Width="25px" ControlStyle-Height="20px" />
with 同
<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>
Here's how you do it, 这是你的做法,
Button btn = (Button)e.Row.Cells[1].Controls[1];
btn.Attributes.Add("onclick","yourFunction()");
Hi you can simply display confirm box on OnclientClick as below 您好,您可以在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?');" />
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.