/// 显示消息提示对话框
/// </summary>
/// <param name="page">当前页面指针,一般为this</param>
/// <param name="msg">提示信息</param>
public void Show(System.Web.UI.Page page,string msg)
{
//page.RegisterStartupScript("message","<script language='javascript' defer>alert('" + msg.ToString() + "');</script>");
page.ClientScript.RegisterStartupScript(page.GetType(),"message","<script language='javascript' defer>alert('" + msg.ToString() + "');</script>");
}
/// <summary>
/// 控件点击消息确认提示框
/// </summary>
/// <param name="page">当前页面指针,一般为this</param>
/// <param name="msg">提示信息</param>
public void ShowConfirm(System.Web.UI.WebControls.WebControl Control,string msg)
{
Control.Attributes.Add("onclick","return confirm('" + msg + "');");
}
/// <summary>
/// 显示消息提示对话框,并进行页面跳转
/// </summary>
/// <param name="page">当前页面指针,一般为this</param>
/// <param name="msg">提示信息</param>
/// <param name="url">跳转的目标URL</param>
public void ShowAndRedirect(System.Web.UI.Page page,string msg,string url)
{
StringBuilder Builder = new StringBuilder();
Builder.Append("<script language='javascript' defer>");
Builder.AppendFormat("alert('{0}');",msg);
Builder.AppendFormat("top.location.href='{0}'",url);
Builder.Append("</script>");
// page.RegisterStartupScript("message",Builder.ToString());
page.ClientScript.RegisterStartupScript(page.GetType(),Builder.ToString());
}
/// <summary>
/// Ajax弹出对话框
/// </summary>
/// <param name="control">一般为UpdataPanle</param>
/// <param name="type">this.Gettype()</param>
/// <param name="script">提示信息</param>
public void AjaxResponeSrcipt(System.Web.UI.Control control,Type type,string script)
{
ScriptManager.RegisterClientScriptBlock(control,type,"click","alert('"+script+"')",true);
}
【实例应用:】
msgBox.AjaxResponeSrcipt(UpdatePanel1,this.GetType(),"请输入正确的信息!");
/// Ajax@R_537_404@面
/// </summary>
/// <param name="control">一般为UpdataPanle</param>
/// <param name="type">this.Gettype()</param>
/// <param name="script">js脚本</param>
public void AjaxTiaoZhuan(System.Web.UI.Control control,string script)
{
ScriptManager.RegisterStartupScript(control,"alert",script,true);
}
public void AjaxResponeSrciptAndBack(System.Web.UI.Control control,string script)
{
ScriptManager.RegisterClientScriptBlock(control,"alert('" + script + "');history.go(-1);",true);
}
public void AjaxResponeSrciptAndClose(System.Web.UI.Control control,string script)
{
ScriptManager.RegisterClientScriptBlock(control,"alert('" + script + "');window.close();",true); } 原文链接:https://www.f2er.com/ajax/165330.html