简体   繁体   English

单击按钮显示叠加/加载图像

[英]showing overlay/loading image on click of button

I am working on asp.net page. 我正在asp.net页面上。 This page has a search button and grid view inside an ajax update panel. 该页面在ajax更新面板中具有一个搜索按钮和网格视图。 Gridview has a button in each row which causes a post back. Gridview每行中都有一个按钮,该按钮会导致发回邮件。 I want to show an overlay /loading image at the top of page when a search button is clicked before gridview is loaded/reloaded so that user can see that data is loading and user can not click search button again. 我想在加载/重新加载gridview之前单击搜索按钮时在页面顶部显示一个叠加/加载图像,以便用户可以看到数据正在加载并且用户不能再次单击搜索按钮。 I tried using ajax updateprogress but that is triggered when gridview row buttons are clicked. 我尝试使用ajax updateprogress,但是当单击gridview行按钮时会触发该事件。 I want the overlay image to appear only on click of search button. 我希望重叠图像仅在单击搜索按钮时出现。 Is there any Jquery plugin available for this functionality or we can customize ajax update progress control ? 是否有任何Jquery插件可用于此功能,或者我们可以自定义ajax更新进度控制?

You can include in your page the jQuery.blockUI plugin, it from the docs: 您可以在页面中包含jQuery.blockUI插件,该插件来自文档:

Lets you simulate synchronous behavior when using AJAX, without locking the browser. 使您可以模拟使用AJAX时的同步行为,而无需锁定浏览器。 When activated, it will prevent user activity with the page (or part of the page) until it is deactivated. 激活后,它将被禁用,直到用户禁用该页面(或页面的一部分)为止。 BlockUI adds elements to the DOM to give it both the appearance and behavior of blocking user interaction. BlockUI向DOM添加元素,以使其具有阻止用户交互的外观和行为。

You activate it using: 您可以使用以下方法激活它:

$.blockUI({ message: '<h1><img src="busy.gif" /> Just a moment...</h1>' });

and deactivate with: 并通过以下方式停用:

$.unblockUI();

You can use it in two ways: 您可以通过两种方式使用它:

FIRST 第一

Handle the beginRequest and endRequest events of the ms ajax PageRequestManager and use blockUI in these events. 处理ms ajax PageRequestManagerbeginRequestendRequest事件,并在这些事件中使用blockUI。

Example code: 示例代码:

Sys.WebForms.PageRequestManager.instance.add_beginRequest(beginRequestHandler);
Sys.WebForms.PageRequestManager.instance.add_endRequest(endRequestHandler);

function beginRequestHandler(sender, args){
    $.blockUI({ message: '<h1><img src="busy.gif" /> Just a moment...</h1>' });
}

function endRequestHandler(sender, args){
    $.unblockUI();
}

SECOND 第二

You can bind and handle ajax global events fired when every ajax call starts, complete 您可以绑定并处理每个ajax调用开始时触发的ajax global events ,完成

$(document).bind("ajaxStart", function() {
    $.blockUI({ message: '<h1><img src="busy.gif" /> Just a moment...</h1>' });
}).bind("ajaxStop", function() {
    $.unblockUI();
});

I successfully used the second solution, but in your case using update panels you can give a try at first too. 我成功地使用了第二种解决方案,但是在您使用更新面板的情况下,您也可以先尝试一下。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM