C# 后台弹出提示
1. 浏览器弹出提示
Response.Write("<script>alert('失败!')</script>"); return;
2. 当前窗口弹出提示,可自动关闭当前窗口
this.Alert("操作成功!", "CloseFrame(true);");//弹出提示并关闭当前窗口 //this.Alert("操作成功!"); //弹出提示 return;
3.带有遮罩层,解决使用1刷新之后出现的样式挤压问题,在当前窗口弹出
RegisterScript("st", "setTimeout(function(){if(alert_h){alert_h(\"删除成功!\", null, null, false);}else{alert(\"删除成功!\");}},300);", true); //setTimeOut(function(){doChk2()}, 1000) return;
1.2 使用引用的方法
/// <summary> /// 弹出提示 /// </summary> /// <param name="messege">提示消息</param> public void Alert(string messege, string func = "") { if (!string.IsNullOrEmpty(func)) { RegisterScript("scriptAlert", "setTimeout(function(){ if(alert_h){alert_h(\"" + messege + "\",function(){$(document.body).removeClass('modal-open');" + func + "});}else{alert(\"" + messege + "\");setTimeout(function () { " + func + " }, 500)}},300);", true); } else { RegisterScript("scriptAlert", "setTimeout(function(){ if(alert_h){alert_h(\"" + messege + "\",function(){$(document.body).removeClass('modal-open');});}else{alert(\"" + messege + "\");}},300);", true); } } /// <summary> /// 注册客户端脚本块 /// </summary> /// <param name="key">键</param> /// <param name="script">脚本</param> /// <param name="type">注册的脚本块类型;true为RegisterStartupScript,否则RegisterClientScriptBlock</param> public void RegisterScript(string key, string script, bool isStartUp) { StringBuilder cstext2 = new StringBuilder(); cstext2.Append("<script type=\"text/javascript\">"); cstext2.Append(script); cstext2.Append("</script>"); ClientScriptManager scriptManager = this.Page.ClientScript; if (!scriptManager.IsClientScriptBlockRegistered(this.GetType(), key)) { if (isStartUp) { scriptManager.RegisterStartupScript(this.GetType(), "clientScript_" + key, cstext2.ToString()); } else { scriptManager.RegisterClientScriptBlock(this.GetType(), "clientScript_" + key, cstext2.ToString()); } } }
Response.Redirect("fansapperror.aspx?type=dataerr");
Response.Write("<script type='text/javascript'>alert('参数错误');</script>");
return;
Response.Write(string.Format("<script type='text/javascript'>alert('{0}');</script>", openId));
return;