Quantcast
Channel: Web Forms
Viewing all articles
Browse latest Browse all 23244

Something is wrong with confirmation box

$
0
0

Hi all, I want to do a confirmation box with a yes and no option. If user clicks yes, the infomation will be entered to the database. However, if the user click no, the user will be brought back to the previous page so that he can edit the fields. I have tried it but when I click no, the infomation also enters the database. Why is this so?

This is my set of codes ;

Aspx

<script type = "text/javascript">
function Confirm() {
var confirm_value = document.createElement("INPUT");
confirm_value.type = "hidden";
confirm_value.name = "confirm_value";
if (confirm("Do you want to continue?")) {
confirm_value.value = "Yes";
} else {
confirm_value.value = "No";
}
document.forms[0].appendChild(confirm_value);
}
</script>


<center><asp:Button ID="Button2" runat="server" CssClass="MainButtons"
onclick="Button2_Click" OnClientClick = "Confirm()" Text="Submit" /></center>

Aspx.cs

public void OnConfirm(object sender, EventArgs e)
{
string confirmValue = Request.Form["confirm_value"];
if (confirmValue == "Yes")
{
this.Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('Thank you! We have received your leave application, the administrator will inform you regarding your make up lesson!')", true);
}
else
{
this.Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('Please make sure everything is correct!')", true);
}
}


Viewing all articles
Browse latest Browse all 23244

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>