Click here to Skip to main content
15,908,634 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a web form that lets a user enters data. When the user clicks the save button there is a message that pops up and asks the user to click ok if they have more data to enter or click no if they are finished entering data. How can I get the yes and no buttons on the popup message?

Here is the code I have now:
C#
ScriptManager.RegisterStartupScript(this, typeof(Page), "myscript", "alert('You Have Successfully Saved the Cohort. If you have Additional Cohorts, Please Click the OK Button to Enter another Cohort. If you are finished entering Cohorts Click the Menu Button at the bottom of the screen');location.href='Page5.aspx';", true);


This code works but I need it to have the yes button to redirect to same page and the no button to redirect to another page.

I have this code that has the Ok and Cancel button but the buttons don't work for some reason. Here is my code:
C#
ScriptManager.RegisterStartupScript(this, this.GetType(), "redirect", "var r = confirm('Data updated successfully. You will now redirected to search page.'); if (r == true) var str= 'Login.aspx'; location.href = 'Gradrate.aspx' ;", true);
Posted
Updated 5-Nov-14 15:18pm
v2

If you can live with the buttons being labelled "OK" and "Cancel", then you can use the confirm method[^].
JavaScript
if(confirm("...")){ 
    /* user clicked "OK" */ 
    location.href = "OkPage.aspx";
} 
else { 
    /* User clicked "Cancel" */
    location.href = "CancelPage.aspx";
}

If you need custom text on the buttons, then you'll need a custom Javascript dialog. jQuery UI[^] is a good place to start.
 
Share this answer
 
Comments
Computer Wiz99 5-Nov-14 21:19pm    
I have this code here:
ScriptManager.RegisterStartupScript(this, this.GetType(), "redirect", "var r = confirm('Data updated successfully. You will now redirected to search page.'); if (r == true) var str= 'Login.aspx'; location.href = 'Gradrate.aspx' ;", true);

It does not redirect to the pages.
Richard Deeming 6-Nov-14 9:17am    
If the user clicks "OK", you set the variable str to "Login.aspx". You then always redirect to "Gradrate.aspx".

Try:
var r = confirm(...); var str = r ? "Login.aspx" : "Gradrate.aspx"; location.href = str;
 
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