Menu ▼

Previous Next

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 : 3/28/2017 8:10:33 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 />
<asp:Button ID="btnGetServerTime" runat="server" Text="Get Server Time" OnClientClick="return getConfirm();"
OnClick="btnGetServerTime_Click" />

 

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();
}


Previous Next




Search dotnetlearners.com