在 Web 表单项目中,我需要打开警报。
我试着这样做
var script = Page.ClientScript;
if (!script.IsClientScriptBlockRegistered(this.GetType(), "SignOffAlert"))
{
script.RegisterClientScriptBlock(this.GetType(), "text", "SignOffAlert");
}
并在视图上添加 js-function
function SignOffAlert() {
alert('The form cannot be submitted!');
}
按钮单击警报不存在
更新 :
这段代码对我有用
var script = Page.ClientScript;
if (!script.IsClientScriptBlockRegistered(this.GetType(), "signOffAlert"))
{
script.RegisterClientScriptBlock(this.GetType(), "signOffAlert", "alert('The form cannot be submitted!');", true);
}