开发者

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

开发者 https://www.devze.com 2022-12-22 05:38 出处:网络
Here\'s my scenario,开发者_JAVA技巧 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:

Here's my scenario,开发者_JAVA技巧 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.


You can just add a JavaScript confirm to the HTML attributes collection.

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

精彩评论

暂无评论...
验证码 换一张
取 消