不好的方法:
Response.Write("<script>alert('aaa');window.navigate('index.aspx','_self')</script>");
好的方法:
string myscript = @"alert('您已经测试过,不允许再次提交!');window.location.href='home.aspx';"; Page.ClientScript.RegisterStartupScript(this.GetType(), "myscript", myscript, true);
注意:请不要使用Response.Write回写JavaScript代码,这样会破坏html的规范,导致页面显示不友好!
弹出“确定”和“取消”对话框,点击“确定”后执行相关操作:
在Page_Load事件中,写入Button1.Attributes["onClick"]="javascript:return confirm('你确认要删除吗?');" ,然后在Button1_OnClick事件中写入您的执行代码。