简体   繁体   中英

How can plain HTML controls be referenced from ASP.Net controls?

Here's my scenario, for which I guess there's a simple solution I'm missing: I want to add a confirm button for each delete link in a MVC app, so when I try this:

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

I get this:

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

Problem is that the asp:ConfirmButtonExtender control is parsed before render happens, therefore no " delete " HTML control is present - yet.

How can I get this right? Thanks in advance.

您可以仅将JavaScript确认添加到HTML属性集合。

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM