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
开发者_StackOverflow中文版 if (oEmployeePersonalData.PhoneDetailUpdate())
{
}
// If No different code
if(confirm("Would you like to delimit the record"))
{
//Delimit record code or return true;
}
else
{
return false;
}
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();"/>
var ans = confirm("Do you want to delimit the record?")
if (ans){
//clicked on yes
}
else{
return false;
}
精彩评论