WEB页面加载时,类似于进度条的东东,可增强页面友好性

两个静态方法: 

namespace AppBLL.Common
{
    public class Function
    {
       /// <summary>
        /// 取得当前程序的虚拟路径以/为结束
        /// </summary>
        /// <returns></returns>
        public static string GetApplicationPath()
        {
            string ApplicationPath = System.Web.HttpContext.Current.Request.ApplicationPath;
            if (!ApplicationPath.EndsWith("/"))
                ApplicationPath += "/";
            return ApplicationPath;
        }

        /// <summary>
        /// WEB页面加载时的进度条,可将此方法放到事件中,需要加载数据的方法之前
        /// </summary>
        public static void ProgressBar()
        {
            HttpContext.Current.Response.Write("<script language=\"javascript\" type=\"text/javascript\">");
            HttpContext.Current.Response.Write("window.onload = function() {");
            HttpContext.Current.Response.Write("document.getElementById('loader_container').style.display='none';");
            HttpContext.Current.Response.Write("document.getElementById('loader_container').style.visibility='hidden';");
            HttpContext.Current.Response.Write("}");
            HttpContext.Current.Response.Write("</script>");
            HttpContext.Current.Response.Write("<div id=\"loader_container\" style=\"position:absolute;top:50%;left:40%\">");
            string ImgFileName = Path.Combine(GetApplicationPath(), "EMCP/images/wait.gif");
            HttpContext.Current.Response.Write("<img id=\"img\" src=\"" + ImgFileName + "\" />正在加载数据,请稍候......");//GIF图自己找个
            HttpContext.Current.Response.Write("</div>");
            HttpContext.Current.Response.Flush();
        }

    }

}

 

使用:

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                Function.ProgressBar();//加载进度条
                refreshGrid();//加载数据
            }
        }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值