开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜