I wrote a script to create a confirmation popup window. However, when I implement it in our aspx.cs page, it seems to be returning incorrect values. Here is my script:
<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 remove this employee from this group?")) {
confirm_value.value = "1";
} else {
confirm_value.value = "2";
}
document.forms[0].appendChild(confirm_value);
}
Button
<asp:Button ID="btnAdd" OnClientClick = "Confirm()" runat="server" ValidationGroup="1" onclick="btnAdd_Click" />
Button click function
protected void btnAdd_Click(object sender, EventArgs e)
{
string confirmValue = Request.Form["confirm_value"];
if (confirmValue == "1")
{
//Do something
}
else
{
//Do something
}
}
When I click cancel the first time, confirmvalue=="1"
, but then if I click ok afterwards, instead of getting 2, it shows confirmvalue=="1,2"
. Why is it giving an error value like this?