How do I get the value of the confirm box selected:
I have this code:
string scriptString = "<script language='JavaScript'> ";
scriptString += "confirm ('Are you sure you want to Close this period.')"开发者_C百科;
scriptString += "</script>";
Response.Write(scriptString);
Is there a way to determine if you select yes or no?
var x = confirm('...')
alert(x)
or
string scriptString = "<script language='JavaScript'> ";
scriptString += "var x = confirm ('Are you sure you want to Close this period.')";
scriptString += "alert(x)";
scriptString += "</script>";
Response.Write(scriptString);
Confirm returns a boolean value indicating ok or cancel (true
means ok, false
means cancel).
You can use it like this:
if(confirm ('Are you sure you want to Close this period.')) {
//they clicked ok
}
else {
//they clicked cancel
}
read more about it here: https://developer.mozilla.org/En/DOM/Window.confirm
You should store the result of the confirm in a hidden field value like this:
if (confirm("Are you sure you want to proceed?")==true){
hiddenField.value = 'true';
return true;
} else {
hiddenField.value = 'false';
return false;
}
and then fetch the value of the hidden field from C#
精彩评论