两个静态方法:
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();//加载数据
}
}