ASP.NET onclientclick c#

时间:2009-09-09 13:33:03

标签: c# asp.net onclientclick

我有一个附带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#函数。

知道问题是什么吗?

2 个答案:

答案 0 :(得分:6)

试试这个:

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

答案 1 :(得分:5)

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

试试这个。