c# - how to use javascript alert so that user can choose - Stack Overflow

I am trying to add an alert box so that the user can choose either Yes or No or Ok and Cancel, but it i

I am trying to add an alert box so that the user can choose either Yes or No or Ok and Cancel, but it is not working correctly. It is my first time I am trying to do this. I am using visual studio 2010. I am not sure if my code is correct. Can anyone please guide me if I am mistaken.

This is my code:

private void AlertWithOption()
  {
     Response.Write("<script language='javascript'>");
     Response.Write("function onsub() ");
     Response.Write("{ ");
     Response.Write("var where_to= confirm: (\"Are You sure?\")");
     Response.Write("if (where_to== true)");
     Response.Write("{ ");
     Response.Write("return true");
     Response.Write(" }");
     Response.Write("else ");
     Response.Write("{");
     Response.Write("return false;");
     Response.Write(" } ");
     Response.Write("} ");
     Response.Write("</script>");
   }

I am trying to add an alert box so that the user can choose either Yes or No or Ok and Cancel, but it is not working correctly. It is my first time I am trying to do this. I am using visual studio 2010. I am not sure if my code is correct. Can anyone please guide me if I am mistaken.

This is my code:

private void AlertWithOption()
  {
     Response.Write("<script language='javascript'>");
     Response.Write("function onsub() ");
     Response.Write("{ ");
     Response.Write("var where_to= confirm: (\"Are You sure?\")");
     Response.Write("if (where_to== true)");
     Response.Write("{ ");
     Response.Write("return true");
     Response.Write(" }");
     Response.Write("else ");
     Response.Write("{");
     Response.Write("return false;");
     Response.Write(" } ");
     Response.Write("} ");
     Response.Write("</script>");
   }
Share Improve this question edited Aug 16, 2011 at 11:28 Shawn Chin 87.1k20 gold badges167 silver badges193 bronze badges asked Aug 16, 2011 at 11:24 mikespiterimikespiteri 9015 gold badges13 silver badges25 bronze badges
Add a ment  | 

6 Answers 6

Reset to default 1

First I would try changing this:

Response.Write("var where_to= confirm: (\"Are You sure?\")");

to this:

Response.Write("var where_to= confirm(\"Are You sure?\")");

(The method is confirm() and not confirm:())

As already mentioned, you had an extra colon in your code. However, there is no need for the lengthy if/then logic, as the confirm javascript method returns a boolean. Your code can be condensed to 3 lines:

Response.Write("<script>");
Response.Write("function onsub() { return confirm(\"are you sure?\"); }");
Response.Write("</script>");

modify this line of code-> Response.Write("var where_to= confirm: (\"Are You sure?\")");
try this->Response.Write("var where_to= confirm ("Are You sure?")");

method confirm() is correct but the string inside should be within double quotes that is confirm("Are You Sure?");

Use confirm() function.

private void AlertWithOption()
  {
    Response.Write("<script language='javascript'>");
    Response.Write("function onsub() ");
    Response.Write("{ ");
    Response.Write("return confirm(\"Are you sure?\")");
    Response.Write("} ");
    Response.Write("</script>");
}

I think you are doing mistake in the syntax of the confirm()

I dont think you want the colon after the confirm, you could do it like this

Response.Write("<script language='javascript'>");
Response.Write("function onsub() ");
Response.Write("{ ");
Response.Write("return confirm(\"Are you sure?\")");
Response.Write("} ");
Response.Write("</script>");

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

相关推荐

  • c# - how to use javascript alert so that user can choose - Stack Overflow

    I am trying to add an alert box so that the user can choose either Yes or No or Ok and Cancel, but it i

    20小时前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

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

关注微信