提交按钮和Javascript

本文关键字:Javascript 按钮 提交 | 更新日期: 2023-09-27 18:00:31

我有一个带有代码的Submit按钮,用于评估c#中的内容,问题是我还想在javascript中添加一个函数,该函数会询问"此文件已经存在,你想替换它吗?"

所以我的问题是,我如何才能同时触发这两种情况?

OnClick="myC#mehod" and also OnClientClick =  return (some javascript);

我能做这个吗?。。。

提交按钮和Javascript

deleteBtn.Attributes["onClick"] = 
    "return confirm('This file already exists, do you want to replace it?');"

更新以进行澄清

<asp:Button ID="btnReplace" runat="server" onclick="btnReplace_Click" Text="Button" OnClientClick="return confirm('This file already exists, do you want to replace it?');" />
protected void btnReplace_Click(object sender, EventArgs e)
{
//Replace the File
}
OnClientClick="return confirm('This file already exists, do you want to replace it?');" 
OnClientClick = "if(!confirm('This file already exists, do you want to replace it?')) return false;"

这比return直接更安全