我想添加一個提醒框,以便用戶可以選擇是或否或確定並取消,但它不能正常工作。我必須做一個數據庫檢查,這是在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。 –