[ASP.net]Loading製作

來源:互聯網
上載者:User

方法很簡單。把代碼放上來大家看看。
打了包成了個控制項。下載地址:
http://upserver4.ys168.com/ys168up/D1/YY1.aspx?f=050P1D8E0E3E5D9D5G6ALI7A00A05AKA03D6A00A08A08I5F9G0E0D9E0D8D6E1A24E6E1D9E5D9C3

下面是源碼:

===================================

using System;

namespace HDControl
{
 /// <summary>
 /// Summary description for Loading.
 /// </summary>
 public class Loading
 {
  private System.Web.UI.Page Sender;
  private string strImagePath;

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

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

  public Loading()
  {
   //
  }

  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();
  }
 }
}


=========================

先在面頁中

using HDControl;

調用方法(在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();

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.