Deepak Goyal

Deepak Goyal

  • NA
  • 64
  • 0

How to use confirm function of java script

Jun 5 2009 12:05 PM
Hi
       I am trying this with Asp .net web application

      I am trying to write some javascript for a confirmation dialog before inserting data into database.
Script is as below

<script type="text/javascript">

function showconfirm()

{

var r=confirm("Press a button");

if (r==true)

  {     
   }

else
  {

  }
}
</script>


To call showconfirm() function I use  OnClientClick ="showconfirm()"

My button look like as follows.

asp:Button ID="Insert" runat="server" Text="Insert" OnClientClick ="showconfirm()" />

I am using code behind technique. Now here if I don't use OnClick="Insert_Click" then  I will not able to insert the data.
And if I use OnClick="Insert_Click"   I will be inserting data every time wether I am clicking OK or cancle in confirmation dialog.


I am not able to understand where i should use OnClick="Insert_Click" event so that on OK click I should be able to insert data and on cancle it should not insert data.
So this problem comes when button tag is like this
<asp:Button ID="Insert" runat="server" Text="Insert" OnClientClick="showconfirm()" OnClick="Insert_Click" />


Please suggest some thing.

Answers (3)