Developer
Developer

Reputation: 8636

How to handle Yes No dialog that was pop-up using Javascript on button click

I am having an update button on my from on clicking update i would like to prompt the user as Do you want to delimit the record with Yes and No buttons. If the user clicks on Yes i would like to execute the code which can delimit the record if not just update the record.

My sample code

protected void btnUpdate1_Click(object sender, EventArgs e)
{
    EmpID = Convert.ToInt32(HiddenField1.Value);

    if (ID == 2)
    {
        oEmployeePersonalData.EmpID = EmpID;
        oEmployeePersonalData.PhoneNumberTypeID = ddlPhoneType.SelectedValue;
        oEmployeePersonalData.PhoneNumber = Convert.ToInt64(txtph1.Text);
        oEmployeePersonalData.EndDate = DateTime.Today.AddDays(-1);

//As per my requirement if i click on yes i would like to execute this code

        if (oEmployeePersonalData.PhoneDetailUpdate())
        {
        }

// If No different code

Upvotes: 0

Views: 2469

Answers (3)

santosh singh
santosh singh

Reputation: 28652

Add following javascript function in the header of the page

 <script type="text/javascript">
        function update() {
            var result = confirm("Do you want to delimit the record?")
            if (result) {

            }
            else {
                return false;
            }


        }

    </script>

and then attach the event to button

 <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button"  OnClientClick="return update();"/>

Upvotes: 0

Adeel
Adeel

Reputation: 19238

var ans = confirm("Do you want to delimit the record?")
if (ans){
    //clicked on yes        
}
else{
     return false;  
}

Upvotes: 0

Rob
Rob

Reputation: 10248

if(confirm("Would you like to delimit the record"))
{
    //Delimit record code or return true;
}
else
{
    return false;
}

Upvotes: 6

Related Questions