asp.net custom Control loading layer _ practical Tips

Source: Internet
Author: User

This article is designed to give you a way to develop a custom control (combined with JS), a simple example that may not be done in a real project.
First look at the effect:

1. Develop the desired effect on the static page

Jquery.extend ({openloading:function (options) {var defaults = {msg: ' Data submission ... ', img: ' Loading.gif '};

    var opts = $.extend (defaults, options); $ ("Body"). Append ("<div class= ' l_overlay ' style= ' position:fixed;top:0;right:0;bottom:0;left:0;z-index:998; width:100%;height:100%;p adding:0 20px 0 0;background-color:gray;display:none; ' ></div><div class= ' l_showbox ' style= ' position:fixed;top:0;left:50%;z-index:1001;opacity:0;filter: Alpha (opacity=0); margin-left:-80px;border:1px solid gray;font-size:12px;font-weight:bold; ' ><div class= ' Loadingword ' style= ' width:122px;height:38px;line-height:38px;border:2px solid #D6E7F2; Background: #fff; ' > Data submission ...</div>

    </div> ");

    var h = $ (document). Height ();

    $ (". L_overlay"). CSS ({"Height": H, ' Display ': ' Block ', ' opacity ': ' 0.4 '}); $ (". L_showbox"). Stop (true). Animate ({' Margin-top ': (H/2-) + ' px ', ' OPACity ': ' 1 '}, 200); 

    }, Closeloading:function () {$ (". L_showbox"). Stop (true) animate ({' margin-top ': ' 250px ', ' opacity ': ' 0 '}, 400);

    $ (". L_overlay"). CSS ({' Display ': ' None ', ' opacity ': ' 0 '});

    $ (". L_overlay"). Remove ();

  $ (". L_showbox"). Remove (); 

 }

});

2.vs New Class Library, new class inherits from WebControl
to add a property:
[Description ("Get and set Trigger ID"), defaultvalue (""), browsable (True), Category ("Miscellaneous")]
public string Targetid {get; set;}
rewrite the OnPreRender method. method to register the JS script, which indicates that the control with ID Targetid displays the load layer when clicked

protected override void OnPreRender (EventArgs e)
{
  if (Page!= null &&!string. IsNullOrEmpty (Targetid))
  {
   Targetid = Getclientid (Targetid);     
   Page.ClientScript.RegisterClientScriptResource (typeof (Loading), "BoControl.Scripts.Jquery.js");     
   This. Page.ClientScript.RegisterStartupScript (typeof (String), "Bocontrol_" + this. ClientID, "$ (\" # "+ Targetid +" \ "). On (\" Click\ ", function () {$.openloading ({msg:\" "+ Text +" \ ", img: \" "" +page.clientscri Pt. GetWebResourceUrl (this. GetType (), "BoControl.Images.loading.gif") + "\"});}; ", true);   
}   
Base. OnPreRender (e); } 

OnPreRender method
  Page.ClientScript.RegisterClientScriptResource (typeof (Loading), " BoControl.Scripts.Jquery.js "); Register jquery
 page.clientscript.getwebresourceurl (this. GetType (), "BoControl.Images.loading.gif"); is to get the Web resource file path, if you do not want to embed the picture file into the DLL, please change to the real path (such as: Images/loading.gif), instead you need to indicate the picture file and the jquery file as follows, and the picture attribute-build operation is: Embedded Resource
 [assembly:webresource ("BoControl.Images.loading.gif", "Image/gif")]//Here you also need to register jquery
Namespace Bocontrol
{
you also need to write the open method and the Close method to facilitate calls in the background code.
  such as:

    <summary>
    ///Open load animation
    ///UpdatePanel registration
    ///</summary>
    ///<param name= "Panel" > UpdatePanel object </param> public
    void Open (UpdatePanel panel)
    {
      if (Page!= null)
      {
        Scriptmanager.registerstartupscript (Panel, panel. GetType (), "openloading", "$.openloading ({msg:\" + Text + "\", img: \ "" + PAGE.CLIENTSCRIPT.GETWEBRESOURCEURL (this). GetType (), "BoControl.Images.loading.gif"); + "\"}); ", true);
      }
       

In general, the development of custom control is not complicated, the above is the entire content of this article, I hope that the study of everyone to help, but also hope that we support the cloud habitat community.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.