views:

44

answers:

1

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.

+3  A: 

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_" })%>
Dustin Laine
Good answer, ++. Still, what I wonder is whether there's a way to refer to HTML controls from ASP ones.
Ariel
Well you can always reference the form from ASP.NET server side code. That is all Web Controls are, just wrapped in all of the Microsoft stuff. Like Request.Form["htmlFormElement"]
Dustin Laine
Did this help or answer what you are looking for, or am I off target?
Dustin Laine
Please mark as answer if it resolved your question.
Dustin Laine