c# - Get value from confirm box - Stack Overflow

How do I get the value of the confirm box selected:I have this code:string scriptString = "<scr

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.')";
scriptString += "</script>";
Response.Write(scriptString);

Is there a way to determine if you select yes or no?

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.')";
scriptString += "</script>";
Response.Write(scriptString);

Is there a way to determine if you select yes or no?

Share Improve this question edited Feb 8, 2011 at 23:29 jcolebrand 16k12 gold badges77 silver badges122 bronze badges asked Feb 8, 2011 at 23:10 user175084user175084 4,64028 gold badges119 silver badges170 bronze badges 1
  • I think you really really need to clarify. Where do you want to know if they said yes or no? On the server or only in the javascript? – jcolebrand Commented Feb 8, 2011 at 23:28
Add a ment  | 

3 Answers 3

Reset to default 1
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/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#

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745333542a4622997.html

相关推荐

  • c# - Get value from confirm box - Stack Overflow

    How do I get the value of the confirm box selected:I have this code:string scriptString = "<scr

    8小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信