最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

c# - Get value from confirm box - Stack Overflow

programmeradmin2浏览0评论

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#

发布评论

评论列表(0)

  1. 暂无评论