提交按钮和Javascript

时间:2011-06-28 14:56:08

标签: c# asp.net

我有一个带有代码的提交按钮,用于评估c#中的内容,问题是我还想在javascript中添加一个函数,询问“此文件已存在,是否要替换它?

所以我的问题是如何触发两者?

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

我可以这样做吗?...

3 个答案:

答案 0 :(得分:1)

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
}

答案 1 :(得分:0)

OnClientClick="return confirm('This file already exists, do you want to replace it?');" 

答案 2 :(得分:-2)

OnClientClick = "if(!confirm('This file already exists, do you want to replace it?')) return false;"

这比return直接

更安全