代码之家  ›  专栏  ›  技术社区  ›  Ariel

如何从中引用普通HTML控件ASP.Net控制?

  •  1
  • Ariel  · 技术社区  · 14 年前

    下面是我的场景,我想我缺少了一个简单的解决方案:我想为MVC应用程序中的每个删除链接添加一个确认按钮,所以当我尝试以下操作时:

    <%= Html.ActionLink("Delete", "Delete", new { id = item.Id }, new { id = "_delete_" })%>
    <asp:ConfirmButtonExtender ID="ConfirmButtonExtender1" runat="server" TargetControlID="_delete_" ConfirmText="Want it or not?" />
    

    我明白了:

    Exception Details: System.InvalidOperationException: The TargetControlID of 'ConfirmButtonExtender1' is not valid. A control with ID '_delete_' could not be found.
    

    删除 “HTML控件存在-尚未。

    1 回复  |  直到 14 年前
        1
  •  3
  •   Dustin Laine    14 年前

    您只需向HTML属性集合添加一个JavaScript确认。

    <%= Html.ActionLink("Delete", "Delete", new { id = item.Id },  new { onclick = "javascript:return confirm('Are you sure?');", id = "_delete_" })%>