我想添加一个提醒框,以便用户可以选择是或否或确定并取消,但它不能正常工作。我必须做一个数据库检查,这是在C彻底完成而不是只需将该功能链接到按钮点击的事件即可。这是我第一次尝试这样做。我正在使用visual studio 2010.我不确定我的代码是否正确。任何人都可以请引导我,如果我错了。Javascript提醒问题
private void AlertWithConfirmation()
{
Response.Write("<script language='javascript'>");
Response.Write("function onsub() ");
Response.Write("{ ");
Response.Write("return confirm(\"Are you sure?\")");
Response.Write("} ");
Response.Write("</script>");
}
这是我完全C#代码:
protected void Import_Click(object sender, EventArgs e)
{
if (!Validation.ValidateDateFormat(dateField.Text))
{
errorMessageLabel.Text = "Invalid Date Format, for example: 1/1/2011 should be 01/01/2011";
}
else
{
//Validation to check if data is already imported
if (BusinessLayerHandler.isImported(dateField.Text) == false)
{
try
{
if (BusinessLayerHandler.isInProgress(dateField.Text)== true)
{
AlertWithConfirmation();
}
}
catch
{
//catch error
}
}
else if (BusinessLayerHandler.isImported(dateField.Text) == true)
{
Alert("That date was already imported");
}
}
你错了,这个代码是毫无意义的。你的目标究竟是什么?如果用户单击“取消”按钮,您试图防止什么? –
您确认后是否尝试过分号? – ibram
您正在向页面写入函数,但触发函数的位置在哪里?还有其他的方式,我认为这应该完成,但考虑到你的例子,好像你希望onsub方法在页面重新加载时触发,在这种情况下,你需要将它附加到文件onload eveent。 –