Raja

Raja

  • 534
  • 2k
  • 345.2k

How to Show yes/no alert box use c# after buttonclick result

Jan 24 2018 6:29 AM
ASPX
  1. <script type = "text/javascript">  
  2. function Confirm() {  
  3. var confirm_value = document.createElement("INPUT");  
  4. confirm_value.type = "hidden";  
  5. confirm_value.name = "confirm_value";  
  6. if (confirm("Do you want to save data?")) {  
  7. confirm_value.value = "Yes";  
  8. else {  
  9. confirm_value.value = "No";  
  10. }  
  11. document.forms[0].appendChild(confirm_value);  
  12. }  
  13. </script>  
Code Behind
  1. protected bool ValidateDuplicate()  
  2. {  
  3. bool result = true;  
  4. Material material = new Material();  
  5. MaterialDataAccess materialDA = new MaterialDataAccess();  
  6. if (hfdMode.Value.Equals("new") || hfdMode.Value.Equals("draft"))  
  7. {  
  8. material.Type = "N";  
  9. }  
  10. else if (hfdMode.Value == "update")  
  11. {  
  12. material.Type = "U";  
  13. }  
  14. material.RequestNo = hfRequestNo.Value;  
  15. material.Description = tbxShortDescription.Text.ToUpper().Replace("'""''");  
  16. materialDA.Material = material;  
  17. materialDA.ValidateCheck();  
  18. if (!materialDA.Message.Text.Equals("SUCCESS"))  
  19. {  
  20. ClientScript.RegisterStartupScript(typeof(Page), "Confirm""<script type='text/javascript'>callConfirm();</script>");  
  21. string confirmValue = Request.Form["confirm_value"];  
  22. if (confirmValue == "Yes")  
  23. {  
  24. // event occures  
  25. }  
  26. else  
  27. {  
  28. // do nothing  
  29. }  
  30. }  
  31. return result;  
  32. }  
I have used above function in inside the button clicl after the success message come continue our further process if not come success to show the popup with yes/no if click no process is stop click no stop the process.but the above code the script is show after the process is completes how to do it?

Answers (2)