来自asp.net的警报框3.5 Code-Behind

时间:2012-09-13 15:26:23

标签: c# javascript jquery asp.net alert

protected void ddlLanguage_SelectedIndexChanged(object sender, EventArgs e)
{           
    if (ddlLanguage.SelectedValue=="es-ES")
    {
        Page page = HttpContext.Current.CurrentHandler as Page;

        page.ClientScript.RegisterStartupScript(typeof(Page), "Script", "<script language='javascript'>alert('All content may not be in Spanish. Do you want to continue...');</script>");            
    }
}

我想要做的只是显示一个简单的警告框,但都是徒劳的......没有任何弹出窗口。需要一些ayudar。

3 个答案:

答案 0 :(得分:2)

您需要验证启动脚本是否尚未注册。查看this post.

您还可以在ASP.NET中构建自定义MessageBox。查看this one

答案 1 :(得分:2)

您也可以通过这种方式实现

protected void ddlLanguage_SelectedIndexChanged(object sender, EventArgs e)
{           
  if (ddlLanguage.SelectedValue=="es-ES")
   {         
      Response.Write("<script>alert('All content may not be in Spanish. Do you want to continue...');</script>");            
   }
}

答案 2 :(得分:0)

ScriptManager.RegisterStartupScript(this.Page,this.GetType(),“showalert”,“Alert Message”,true);

这适用于没有回发的我 试试这个