Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Example Analysis of loading layer in Asp.net Custom Control

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report