Search code examples
asp.netmessagebox

Display confirmation box in ASP.NET using JavaScript


I need to show the confirm box "Are you sure You Want To continue?" If "Yes" I need the ASP.NET textbox value to be cleared out. Otherwise it should not be cleared.


Solution

  • function doConfirm(){
      if (confirm("Are you sure you want to continue?")){
         var mytxtbox = document.getElementById('<% =myAspTextBox.ClientID %>');
         mytxtbox.value = '';
      }    
    
    }
    

    Note the myAspTextBox refers to the name of the asp:textbox controls ID property

    <asp:textbox ID="myAspTextBox" runat="server" OnClientClick="javascript:doConfirm();"
    

    Hope this helps