4

如何将 onclentclick 和 onclick 事件从后面的代码添加到图像按钮。我写了一些代码,它显示了 onclientclick 事件的确认消息,但没有触发 onclick 事件。

我的代码如下..

ImageButton img = new ImageButton();
img.ID = "img1";
img.Visible = true;
img.OnClientClick = "alert(confirm('Are you sure you want to delete folder with files ?'));";
img.Click += new ImageClickEventHandler(img_Click);
img.ImageUrl = "~/images/admin/remove.png";

事件的代码是:

void img_Click(object sender, ImageClickEventArgs e)
{
 //code what i want to implement   
}
4

2 回答 2

1

改变OnClientClick如下

   img.OnClientClick = "return confirm('Are you sure you want to delete folder with files ?');";

或者您可以在您的 aspx 页面中添加脚本作为方法,然后从OnClientClick

img.OnClientClick ="ConfirmDelete()";


<script type="text/javascript">
function ConfirmDelete()
  {
      return confirm('Are you sure you want to delete folder with files ?');
  }
</script>
于 2013-08-15T07:19:45.097 回答
0

我认为你写的那行:

img.OnClientClick = "alert(confirm('Are you sure you want to delete folder with files ?'));";

应替换为:

img.OnClientClick = "return confirm('Are you sure you want to delete folder with files ?');";

因为确认框不需要警报。

于 2013-08-15T07:17:44.787 回答