javascript C# loading

 

两个不同版本的.一个是javascript,一个C#的.记得以前的贴子还写过一个FLASH的,如果需要,请查找

原理.利用WEB页面的onLoad方法.使加载完后的内容显示.

javascript版本:

    <script type="text/javascript">
        window.οnlοad=function()
        {
            objLoad = document.getElementById('divLoad');
            objLoad.style.display='none';
            objTree = document.getElementById('divTree');
            objTree.style.display='block';
        }
    </script>

   <div id="divLoad">
        <img src="img/loading.gif" />
        &nbsp;正在加载......
    </div>

    <div id="divTree" style="display:none;">
               内容......................  
    </div>

C#版本:

using System;

/// <summary>
/// Loading 加载条类
///
/// 调用方法(在Page_Load里):
/// LoadingControl.Loading objLoad = new LoadingControl.Loading( this,"Images/loading.gif" );
/// objLoad.Load();
/// 或:
/// LoadingControl.Loading objLoad = new LoadingControl.Loading( );
/// objLoad.Page = this;
/// objLoad.ImageMapth = "Images/loading.gif";
/// objLoad.Load();
/// </summary>
public class Loading
{
    private System.Web.UI.Page Sender;
    private string strImagePath;

    public Loading()
    {
   
    }

    public object Page
    {
        get
        {
            return Sender;
        }
        set
        {
            Sender = (System.Web.UI.Page)value;
        }
    }

    public string ImageMapth
    {
        get
        {
            return strImagePath;
        }
        set
        {
            strImagePath = value;
        }
    }

    public Loading(object sender)
    {
        Page = sender;
    }

    public Loading(object sender, string ImageMapth)
    {
        Page = sender;
        this.strImagePath = ImageMapth;
    }

    /// <summary>
    /// Load script to page
    /// </summary>
    public void Load()
    {
        if (!this.Sender.IsClientScriptBlockRegistered("startScript"))
        {
            this.Sender.RegisterClientScriptBlock("startScript", this.Start());
            this.Sender.RegisterStartupScript("endScript", this.End());
        }
    }

    /// <summary>
    /// Script start.
    /// </summary>
    /// <returns></returns>
    private string Start()
    {
        string strStyle = "BORDER-TOP-STYLE: none; BORDER-RIGHT-STYLE: none; BORDER-LEFT-STYLE: none; BORDER-BOTTOM-STYLE: none";
        System.Text.StringBuilder strScript = new System.Text.StringBuilder();
        strScript.Append("<div id=/"loading/">");
        strScript.Append("<table width=/"100%/" height=/"100%/" border=/"0/" cellpadding=/"0/" cellspacing=/"0/" style=/"" + strStyle + "/">");
        strScript.Append("<tr style=/"" + strStyle + "/" ><td width=/"100%/" height=/"100%/" align=/"center/" valign=/"middle/" style=/"" + strStyle + "/">");
        strScript.Append("<img src=/"" + this.ImageMapth + "/" border=/"0/">");
        strScript.Append("</td></tr>");
        strScript.Append("</table></div>");
        return strScript.ToString();
    }

    /// <summary>
    /// Script end.
    /// </summary>
    /// <returns></returns>
    private string End()
    {
        System.Text.StringBuilder strScript = new System.Text.StringBuilder();
        strScript.Append("<script language=/"javascript/">");
        strScript.Append("window.document.getElementById(/"loading/").style.display = /"none/";");
        strScript.Append("</script>");
        return strScript.ToString();
    }
}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值