C# Webforms show Loading indicator during code execution(C# Webforms 在代码执行期间显示加载指示器)
问题描述
我拥有的 Webforms 应用程序数据量很大,它主要是执行 ADO.net 操作的 ASP 控件.我有 5-15 秒的加载时间,这是正常的,但我想让用户更明显地知道他们的请求正在被处理.
The Webforms application I have is very data heavy, it's mostly ASP controls doing ADO.net operations. I have loading times of anywhere from 5-15 seconds, which is normal, but I'd like to make it more obvious to the user that their request is being processed.
我想要做的是添加一个加载图像或某种视觉元素,在服务器代码运行时显示.
What I'd like to do is add a loading image or some kind of visual element that will show when server code runs.
ASP:
<telerik:RadButton ID="OKbutton" runat="server"
Skin="WebBlue"
Text="OK">
</telerik:RadButton>
C#:
private SqlDataReader dr = null;
protected void OKbutton_Click(object sender, EventArgs e)
{
//Long running query
string query = "UPDATE Employees SET Salary = 12345 WHERE EmployeeID = 123"
SqlCommand cmd = new SqlCommand(query, db.DbConnection);
dr = cmd.ExecuteReader();
}
推荐答案
您可以为此使用 jquery BlockUI.演示的链接.这应该适用于您的所有情况(完全回发和部分回发).
You can use jquery BlockUI for this. Link to Demo. This should work for all your cases (full postback and partial postback).
为beginRequest和endRequest
添加事件处理程序v=vs.100).aspx" rel="noreferrer">PageRequestManager.在 BeginRequestHandler
中,您可以使用自定义设置开始显示加载指示器,并在 EndRequestHandler
中隐藏加载指示器.如果您不想阻止整个页面,那么此插件可以选择显示元素的加载指示器(例如,在页面的 div 内,请参阅演示页面)
Add event handlers for beginRequest
and endRequest
of PageRequestManager.
In the BeginRequestHandler
you can start displaying the loading indicator with your customized settings and in the EndRequestHandler
you hide the loading indicator. If you don't want to block the whole page then this plugin has option to show the loading indicator for an element (eg. within a div in the page, refer the demo page)
<script type="text/javascript">
function pageLoad(sender, args) {
var prm = Sys.WebForms.PageRequestManager.getInstance();
prm.add_beginRequest(BeginRequestHandler);
prm.add_endRequest(EndRequestHandler);
}
function BeginRequestHandler(sender, args) {
showLoadingUI();
}
function EndRequestHandler(sender, args) {
$.unblockUI();
}
function showLoadingUI() {
$.blockUI({
message: '<h3><img src="../images/ajax-loader.gif" /> <br /> <span style="font-family: Tahoma,Verdana,Arial, Sans-Serif; font-size: 12px; color: #1390c6;"> Loading...</span></h3>',
showOverlay: true,
css: {
width: '130px', height: '110px',
border: 'none',
padding: '10px',
'-webkit-border-radius': '10px',
'-moz-border-radius': '10px',
opacity: .9
}
});
}
</script>
还要记住从 CDN 或本地应用程序中引用 jquery 和 blockui 插件脚本.
Also remember to reference the jquery and the blockui plugin scripts from either CDN or from your local application.
<script type="text/javascript" src="jquery1.11.1.min.js"></script>
<script type="text/javascript" src="jquery.blockUI.js"></script>
这篇关于C# Webforms 在代码执行期间显示加载指示器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:C# Webforms 在代码执行期间显示加载指示器


- Web Api 中的 Swagger .netcore 3.1,使用 swagger UI 设置日期时间格式 2022-01-01
- C# 中多线程网络服务器的模式 2022-01-01
- MoreLinq maxBy vs LINQ max + where 2022-01-01
- 在哪里可以找到使用中的C#/XML文档注释的好例子? 2022-01-01
- 如何用自己压缩一个 IEnumerable 2022-01-01
- 良好实践:如何重用 .csproj 和 .sln 文件来为 CI 创建 2022-01-01
- 输入按键事件处理程序 2022-01-01
- C#MongoDB使用Builders查找派生对象 2022-09-04
- WebMatrix WebSecurity PasswordSalt 2022-01-01
- 带有服务/守护程序应用程序的 Microsoft Graph CSharp SDK 和 OneDrive for Business - 配额方面返回 null 2022-01-01