日期:2014-05-17  浏览次数:20991 次

asp.net消息提示框代码

/// <summary>
    /// 显示消息提示对话框
    /// </summary>
    /// <param name="page">当前页面指针,一般为this</param>
    /// <param name="msg">提示信息</param>
    public static void Show(Page page, string msg)
    {
        ClientScriptManager cs = page.ClientScript;
        String csname = "PopupScript";
        Type cstype = page.GetType();

        cs.RegisterStartupScript(cstype, csname, "<script language=\"javascript\">alert(\"" + msg + "\");</script>");
    }

    /// <summary>
    /// 显示消息对话框并进行页面跳转
    /// </summary>
    /// <param name="page">当前页面指针,一般为this</param>
    /// <param name="msg">提示信息</param>
    /// <param name="url">目标URL</param>
    public static void ShowAndRedirect(Page page, string msg, string url)
    {
        ClientScriptManager cs = page.ClientScript;
        String csname = "PopupScript";
        Type cstype = page.GetType();

        cs.RegisterStartupScript(cstype, csname, "<script language=\"javascript\">alert(\"" + msg + "\");location.href=\"" + url + "\"</script>");
    }

    public static void ShowAndRedirect(Page page, string msg, string url, string flag)
    {
        ClientScriptManager cs = page.ClientScript;
        string csname = "PopupScript";
        Type cstype = page.GetType();

        cs.RegisterStartupScript(cstype, csname, "<script language=\"javascript\">alert(\"" + msg + "\");" + flag + ".location.href=\"" + url + "\"</script>");

    }

    public static void ShowAndBack(Page page, string msg)
    {
        ClientScriptManager cs = page.ClientScript;
        string csname = "PopupScript";
        Type cstype = page.GetType();

        cs.RegisterStartupScript(cstype, csname, "<script language=\"javascript\">alert(\"" + msg + "\");history.back();</script>");
    }
?