How do I add a confirmation popup on a button (GET POST action in MVC)?
Posted
by user54197
on Stack Overflow
See other posts from Stack Overflow
or by user54197
Published on 2010-06-17T16:09:57Z
Indexed on
2010/06/17
16:13 UTC
Read the original article
Hit count: 614
I have a get/post/JSON function on an aspx page. This page adds data entered in a textbox to a table populated by javascript. When the user select the submit button. If the textbox is not empty, have a popup button telling the user the data in the textbox is not saved in the table. How do I have a confirm "ok/cancel" popup display on the post action in the Controller? I made a quick summary of what my code looks like.
...
<% using (Html.BeginForm("AddName", "Name", FormMethod.Post, new { id = "AddNameForm" })) { %>
...
<table id="displayNameTable" width= "100%">
<tr>
<th colspan="3">Names Already Added</th>
</tr>
<tr>
<td style="font-size:smaller;" class="name"></td>
</tr>
</table>
...
<input name="Name" id="txtInjuryName" type="text" value="<%=test.Name %>" />
...
<input type="submit" name="add" value="Add"/>
<% } %>
<form id="form1" runat="server">
string confirmNext = "";
if (test.Name == "")
{
confirmNext = "return confirm('It seems you have a name not added.\n\nAre Continue?')";
}%>
<input type="submit" name="getNext" value="Next" onclick="<%=confirmNext%>" />
</form>
© Stack Overflow or respective owner