Click here to Skip to main content
15,889,462 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi
I want to display an Alert MessageBox after I clicked save button on the form(Save Program), then after I clicked OK on the Alert MessageBox I want to call Confirmatiom MessageBox, then when I clicked OK it should take to another form(Add Phase) but if I clicked Cancel it should take me back to Save Program form.

Here is my javascript function(aspx code)

C#
function display()
      {
          alert("Program Has Been Successfully Create");
          if (confirm("Do you want to create phases?") == true) 
          {
            window.location = "CreateProgramPhase.aspx";

           } 
           else 
           { 
           window.location = "CreateProgram.aspx"; 
           }
         return false;
     }


And my save button(cs code)

C#
protected void btnSave_Click(object sender, EventArgs e)
   {
       AddProgram();

       btnSave.Attributes.Add("onClick", "return  display();");

   }


I can't display CreateProgramPhase Form after I clicked OK in the Confirmatiom MessageBox.


Thanks
Posted
Updated 20-Jun-12 3:40am
v4

try below javascript function

JavaScript
function display()
      {
          alert("Program Has Been Successfully Create");
          if (confirm("Do you want to create phases?") == true) 
          {
            window.location = "CreateProgramPhase.aspx";
           } 
           else 
           { 
           window.location = "CreateProgram.aspx"; 
           }
 return true;
       }
 
Share this answer
 
v2
Comments
Sergey Alexandrovich Kryukov 20-Jun-12 15:05pm    
[OP commented:]
Thanks for reply but still not working.
Sergey Alexandrovich Kryukov 20-Jun-12 15:06pm    
What the hell is "not working"? And how about running it under debugger? And how do you know that your display is ever called?
--SA
Change your javascript
function display() {
           alert("Program Has Been Successfully Create");
          if (confirm("Do you want to create phases?") == true) {
               window.location = "CreateProgramPhase.aspx";

           }
          else {
               window.location = "CreateProgram.aspx";
          }
       }
   </script>

and change button click event as

C#
protected void btnSave_Click(object sender, EventArgs e)
   {
AddProgram();
       if (ClientScript.IsClientScriptBlockRegistered("test1212") == false)
           ClientScript.RegisterStartupScript(this.GetType(), "test1212", "<script>display();</script>");
   }
 
Share this answer
 
v3
Try the following code with debugger
JavaScript
function display()
      {
         debugger;          
          alert("Program Has Successfully Create");
          if (confirm("Do you want to create phases?")) 
          {
            window.location = "CreateProgramPhase.aspx";
           } 
           else 
           { 
           window.location = "CreateProgram.aspx"; 
           }
 return true;
       }

Read following link for debugging technique
http://sixrevisions.com/javascript/javascript-debugging-techniques-in-ie-6/[^]
C#
button.Attributes.Add("onclick", "javascript:display()")
 
Share this answer
 
C#
Rewrite function this way
function display()
      {
          alert("Program Has Been Successfully Create");
      var answer = window.confirm('Do you want to create phases?');
          if (answer == true)
            window.location = "CreateProgramPhase.aspx";
          else
            window.location = "CreateProgram.aspx";
          return answer;
     }
 
Share this answer
 

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