private void Button2_Click(object sender, System.EventArgs e) { String scriptString = "<script language=javascript>"; scriptString += "alert('数据写入成功!')"; scriptString += "</script>"; if(!this.IsStartupScriptRegistered("Startup")) this.RegisterStartupScript("Startup", scriptString); } |
再进一步,可以实现提示后跳转到其它页面
private void Button2_Click(object sender, System.EventArgs e) { String scriptString = "<script language=javascript>"; scriptString += "alert('数据写入成功!');"; scriptString += "window.location='test.aspx';"; scriptString += "</script>"; if(!this.IsStartupScriptRegistered("Startup")) this.RegisterStartupScript("Startup", scriptString); } |
如果把这个通用函数放到一个公共类中时要注意要把当前的Page作为参数传递过去才行
function static void showmessage(System.Web.UI.Page mypage,string Info)
{
String scriptString = "<script language=javascript>";
scriptString += "alert('“+Info+“')";
scriptString += "</script>";
if(!mypage.IsStartupScriptRegistered("Startup"))
mypage.RegisterStartupScript("Startup", scriptString);
}
如果把这个通用函数放到一个公共类中时要注意要把当前的Page作为参数传递过去才行
function static void showmessage(System.Web.UI.Page mypage,string Info)
{
String scriptString = "<script language=javascript>";
scriptString += "alert('“+Info+“')";
scriptString += "</script>";
if(!mypage.IsStartupScriptRegistered("Startup"))
mypage.RegisterStartupScript("Startup", scriptString);
}