在客户端发出警报消息后继续执行代码

Continue execution of the code after alert message from clientside

本文关键字:继续 执行 代码 消息 客户端      更新时间:2023-09-26

我必须使用webappsplication发送邮件。一切都很好,但如果没有选择附件,我必须显示一条确认消息。在确认框中,当单击ok时,代码的执行应该继续,当单击cancel按钮时,代码应该返回。

这是我的代码

背后的代码

 protected void btnSend_Click(object sender, EventArgs e)
  {
string str = "Are you sure, you want to proceed without attachment?";  
this.ClientScript.RegisterStartupScript(typeof(Page), "Popup", "ConfirmApproval('" + str + "');", true);
...Send mail code goes here
}

ASPX-

function ConfirmApproval(objMsg)
{
    if(confirm(objMsg))
    {
        alert("execute code.");
        return true;
    }    
    else
        return false;    
}

它运行良好,即当点击ok按钮时,会显示"执行代码"的警报。我想继续执行代码,而不是显示警报。我们将如何从客户端做到这一点???

试试这个代码,

protected void Page_Load(object sender, EventArgs e)
{
    btnSend.Attributes.Add("onclick","return confirm('execute code');");
}

您需要使用confirm("execute code")而不是"alert"。希望能有所帮助:)

var agreed = confirm("execute code");
if(agreed) {
    //do something
} else {
    return false;
}

我向您展示了一种使用暴力的方法。

将代码放在您创建的任何网页的pageload(sender,e)中。现在通过XHR呼叫。

(这可能是一个糟糕的答复)。