Get the App
SLTechnology News&Howtos  ›  Development  › 

Example Analysis of loading layer in Asp.net Custom Control

Shulou Source: shulou.com Published: 2022-06-03 12:50:55 09月12日 Update

This article mainly introduces the example analysis of the loading layer in the Asp.net custom control, which has a certain reference value, and interested friends can refer to it. I hope you can learn a lot after reading this article.

Let's take a look at the effect:

1. Develop the desired effect in a static page

JQuery.extend ({openloading: function (options) {var defaults = {msg: 'data submission...', img: 'loading.gif'}; var opts = $.extend (defaults, options); $("body") .append ("

Data submission. "); var h = $(document). Height (); $(" .l _ overlay "). Css ({" height ": h, 'display':' block', 'opacity':' 0.4'}); $(" .l _ showbox ") .stop (true). Animate ({'margin-top': (h / 2-58) +' 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 creates a new class library, which inherits from WebControl

Add attributes:

[Description ("get and set trigger ID"), DefaultValue ("), Browsable (true), Category (" Miscellaneous ")]

Public string TargetID {get; set;}

Override the OnPreRender method. Method, which instructs a control whose ID is TargetID to display 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.ClientScript.GetWebResourceUrl (this.GetType (), "BoControl.Images.loading.gif") + "\"}); ", true);} base.OnPreRender (e);}

In the 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 path of the Web resource file. If you do not want to embed the image file into dll, please change it to the real path (e.g. Images/Loading.gif). Instead, you need to specify the picture file and JQuery file as follows, and the image attributes-generate operation is: embedded resources.

[assembly: WebResource ("BoControl.Images.loading.gif", "image/gif")] / / you also need to register for JQuery here

Namespace BoControl

{

You also need to write Open methods and Close methods to facilitate calls in background code.

Such as:

/ Open load animation / UpdatePanel register / UpdatePanel object 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);}} Thank you for reading this article carefully. I hope the article" sample Analysis of loading layer in Asp.net Custom Control "shared by the editor will be helpful to you. At the same time, I also hope that you will support and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

Tags: Methods files articles controls pictures examples add analysis properties effects data scripts resources paths code value interests animation and at the same time background Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno vpn OPPO Reno Shulou Tech Info NVidia Apple