[英]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 //如果没有其他代码
if(confirm("Would you like to delimit the record"))
{
//Delimit record code or return true;
}
else
{
return false;
}
var ans = confirm("Do you want to delimit the record?")
if (ans){
//clicked on yes
}
else{
return false;
}
Add following javascript function in the header of the page 在页面标题中添加以下javascript函数
<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();"/>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.