ASP.NET中常用输出JS脚本的类实例(3)

#region 新版本
    /// <summary>
    /// 弹出JavaScript小窗口
    /// </summary>
    /// <param>窗口信息</param>
    public static void Alert(string message, Page page)
    {
        #region
        string js = @"<Script language='JavaScript'>
                    alert('" + message + "');</Script>";
        //HttpContext.Current.Response.Write(js);
        if (!page.ClientScript.IsStartupScriptRegistered(page.GetType(), "alert"))
        {
            page.ClientScript.RegisterStartupScript(page.GetType(), "alert", js);
        }
        #endregion
    }

/// <summary>
    /// 弹出消息框并且转向到新的URL
    /// </summary>
    /// <param>消息内容</param>
    /// <param>连接地址</param>
    public static void AlertAndRedirect(string message, string toURL, Page page)
    {
        #region
        string js = "<script language=javascript>alert('{0}');window.location.replace('{1}')</script>";
        //HttpContext.Current.Response.Write(string.Format(js, message, toURL));
        if (!page.ClientScript.IsStartupScriptRegistered(page.GetType(), "AlertAndRedirect"))
        {
            page.ClientScript.RegisterStartupScript(page.GetType(), "AlertAndRedirect", string.Format(js, message, toURL));
        }
        #endregion
    }

/// <summary>
    /// 回到历史页面
    /// </summary>
    /// <param>-1/1</param>
    public static void GoHistory(int value, Page page)
    {
        #region
        string js = @"<Script language='JavaScript'>
                    history.go({0}); 
                  </Script>";
        //HttpContext.Current.Response.Write(string.Format(js, value));
        if (!page.ClientScript.IsStartupScriptRegistered(page.GetType(), "GoHistory"))
        {
            page.ClientScript.RegisterStartupScript(page.GetType(), "GoHistory", string.Format(js, value));
        }
        #endregion
    }

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wjzdgs.html