Click here to Skip to main content
15,881,139 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
protected void Page_Load(object sender, EventArgs e)
    {
        int result = 0;
         Response.Write("<script>var a=confirm('You are about to change the shipping status of Order Id:! Are you sure you want to continue?');if(a==true){ "+result++ +"}; </script>");
         Response.Write("" + result);
    }


Hi All,
I am sharing a small piece of code here. My objective is that the 'result' variable value should increase only if 'a' is true. But it is not working irrespective of whether i am clicking on 'OK' or 'Cancel' button of the confirm box. It is always increasing the result variable. Please let me know the reason and any workaround.
Posted

1 solution

Response.Write("<script>var a=confirm('You are about to change the shipping status of Order Id:! Are you sure you want to continue?');if(a==true){ "+ result++ +"}; </script>");

Your script will generate following script at server and send to client. result++ will be evaluated at its encounter on server itself. Your confirm box doesn't serve anything but a prompt. You may like to use a hidden variable or something and increment it through your script.
<script>var a=confirm('You are about to change the shipping status of Order Id:! Are you sure you want to continue?');if(a==true){1}; </script>
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900