我有以下代码,用于提示用户问题已提交,然后刷新页面:
protected void ButtonSubmitQuestionClick(object sender, EventArgs e)
{
-- A whole bunch of code that does stuff --
//close window
ScriptManager.RegisterStartupScript(Page, Page.GetType(), "alert", "alert('Your question has been submitted!');window.close();", true);
Response.Redirect("~/QA_QuestionIntake.aspx");
}
问题是,弹出窗口从未出现,大概是因为页面立即刷新。我怎样才能让代码在警报上暂停,直到用户按下按钮?
将重定向逻辑移到 JS 块中。不能将服务器端代码与客户端 js 混合,并处理执行顺序。