Confirmation message in javascript


We use the confirm function to get the confirmation from the user.

Note : to prevent postback of a button click based on the confirmation by the user, you need to return true/ false from the calling function and from the calling event. (OnClientClick="return getConfirm();")

Page loaded at
Server Time: 11/3/2018 1:51:08 AM




Code Sample :

Design
<script language="javascript"> function getConfirm { return confirm("Are you sure want to get the server time?"); } </script> Page loaded at Server Time : <asp:Label ID="lblTime" runat="server"></asp:Label> <br /> <br />

CS Page
protected void Page_Load(object sender, EventArgs e) { if(!IsPostBack) lblTime.Text = DateTime.Now.ToString(); } protected void btnGetServerTime_Click(object sender, EventArgs e) { lblTime.Text = DateTime.Now.ToString(); }