Wednesday, 19 April 2017

How to use JavaScript Confirm Dialog Box in Asp.Net?

In this post, I will explain how to use JavaScript Confirm dialog box in Asp.Net?. 

In application many time a situation comes where programmer want the user to verify or accept something and this can be done by using JavaScript Confirm Dialog box. 
JavaScript supports three important types of dialog boxes. These dialog boxes can be used to raise an alert, or to get confirmation on any input or to have a kind of input from the users. Here we will discuss Confirm Dialog Box.

A confirm dialog box is mostly used to verify or accept something from a userA confirm dialog box is displayed using a method confirm(). A confirm() method takes one parameter.

A confirm dialog box gives two buttons: 
1. OK - If a user clicks the OK button, confirm() method returns true
2. Cancel - If a user clicks the Cancel button, confirm() method returns false

HTML Code - 

<html lang="">
   <head>
     <title>How to use JavaScript Confirm Dialog Box in Asp.Net</title>
      <script type="text/javascript">
            function getConfirmation(){
               var retVal = confirm("Do you want to proceed ?");
               if( retVal == true ){
                document.getElementById("ans").innerText = "User wants to proceed!!!";
                  return true;
               }
               else{
                   document.getElementById("ans").innerText = "User don't want to proceed!!!";
                  return false;
               }
            }
      </script>
   </head>

   <body>

      <form>
         <input type="button" value="Click Me To Get Confirmation" onclick="getConfirmation();" />
         </br>
         <h1 id="ans"></h1>
      </form>
   </body>
</html>

0 comments:

Post a Comment

Please do not enter any spam link in the message box.