试试这个方法:
句法
public void RegisterOnSubmitStatement (
Type type,
string key,
string script
)
用法
将此代码放在页面加载上会使脚本在网络表单的每次提交点击时触发。
if (!script.IsClientScriptBlockRegistered(this.GetType(), "SubmitScript"))
{
script.RegisterOnSubmitStatement(this.GetType(), "SubmitScript", "alert('Submit Clicked')");
}
考虑下面的代码
protected void Page_Load(object sender, EventArgs e)
{
ClientScriptManager script = Page.ClientScript;
if (!script.IsClientScriptBlockRegistered(this.GetType(), "SubmitScript"))
{
script.RegisterOnSubmitStatement(this.GetType(), "SubmitScript", "return confirm('Are you sure to continue')");
}
}
protected void btnSubmit_Click(object sender, EventArgs e)
{
Response.Write("Form is Submitted.");
}