Bhavesh Vankar

Bhavesh Vankar

  • 760
  • 1.1k
  • 88.2k

Confirm Message in web asp.net c#

Dec 30 2020 10:15 AM
i have written below code to confirm message before save record into database. but when i impliment inside my project its not working. 
 
Javascript code written into my web page after after head tag.  
i have used (!ispostback) in side my project kindly help me what is wrong. the page is not do any process after button press.  
  1. <script type="text/javascript">  
  2.           function ConfirmMessage() {  
  3.               var selectedvalue = confirm("Do you want to save data?");  
  4.               if (selectedvalue) {  
  5.                   document.getElementById('<%=txtconformmessageValue.ClientID %>').value = "Yes";  
  6.               } else {  
  7.                   document.getElementById('<%=txtconformmessageValue.ClientID %>').value = "No";  
  8.               }  
  9.           }  
  10.     </script>  
 added hidden field for the store value. 
  1. <asp:HiddenField ID="txtconformmessageValue" runat="server" />  
code behind code for save button code. 
  1. if (txtconformmessageValue.Value == "Yes")  
  2.                    {  
  3.                        Page.ClientScript.RegisterStartupScript(this.GetType(), "Confirm value""alert('Record Has Been Saved')"true);  
  4.                    }  
  5.                    else  
  6.                    {  
  7.                        return;  
  8.                        //Page.ClientScript.RegisterStartupScript(this.GetType(), "Confirm value", "alert('You have clicked on CANCEL.')", true);  
  9.                    }  
 

Answers (9)