Showing posts with label Dialog Box. Show all posts
Showing posts with label Dialog Box. Show all posts

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>

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

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

While writing program much time a situation comes where the programmer wants to pop-up a text box to get user input and this can be done by using JavaScript Prompt 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 Prompt Dialog Box. 

A Prompt dialog box is very useful when we want to pop-up a text box to get user input. User needs to fill the text box field and then click OK.
A Prompt dialog box is displayed using a method prompt(). The prompt method takes two parameters: 
1. A label which you want to display
2. A default string to display in the text box

A Prompt dialog box gives two buttons: 
1. OK - If a user clicks the OK button, prompt() method returns a value from a text box
2. CancelIf a user clicks the Cancel button, the prompt() method returns a null value

HTML Code - 
<html lang="">
   <head>
      <title>How to use JavaScript Prompt Dialog Box in Asp.Net</title>
      <script type="text/javascript">
           function PromptUser(){
               var retVal = prompt("Please enter your choice (1,2 or 3) : ", "Enter your choice here");
               document.getElementById("enteredChoice").innerText = "Your choice is : " + retVal;
            }
       </script>
   </head>
   
   <body>
      <form>
         <input type="button" value="Click me to propmt a textbox" onclick="PromptUser();" />
         </br>
         <h1 id="enteredChoice"></h1>
      </form>
   </body>
</html>

Tuesday, 18 April 2017

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

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

While writing program much time a situation comes where the programmer wants to give warning or alert message to the user and this can be done by using JavaScript Alert 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 Alert Dialog Box.

An alert dialog box is mostly used to give a warning message to the users or alert dialog box can be used to give informative messages to the user. 

An alert dialog box is displayed using a method alert(). The alert method takes one parameter (A label which you want to display in the text box. The alert dialog box gives only one button OK to select and proceed.

For example, if one input field requires to enter some text but the user does not provide any input, then as a part of the validation, you can use an alert box to give a warning message.

HTML Code - 

<html  lang="">
   <head>
      <title>How to use JavaScript Alert Dialog Box in Asp.Net</title>
      <script type="text/javascript">
            function GiveAlert() {
               alert ("This is a warning message for user!");
            }
      </script>
   </head>

   <body>
      <form>
         <input type="button" value="Click Me For Alert Dialog Box" onclick="GiveAlert();" />
      </form>
   </body>
</html>