PleaseWaitButton ASP.NET Server Control

ASP.NET前后端用户安全管理技术全解析 本文系统介绍ASP.NET Core中用户管理的核心技术,涵盖注册登录、密码加密(PBKDF2)、JWT身份认证及AccessToken/RefreshToken机制。通过轻量级Web API项目演示,强调安全实践:密码明文不存储,使用加盐哈希;登录后生成带有效期的JWT令牌,结合短时效AccessToken与安全存储的RefreshToken实现无状态身份验证,提升系统安全性与用户体验。 阅读详情

http://www.codeproject.com/aspnet/PleaseWaitButton.asp

 

Introduction

It is often useful upon a form submission in a web application to display a "please wait" message, or animated .gif image, particularly if the submission process lasts a few seconds or more. I recently developed a survey submission application in which internal users upload excel spreadsheets through a web page. The application inserts the uploaded data from the spreadsheets into a database. The upload/insert process may only take a few seconds, but even a few seconds on the web is a noticeable wait. When testing, some users clicked the upload button repeatedly; it was useful to provide a visual clue that the upload was underway. For that matter, it was useful to hide the upload button altogether, preventing multiple clicks. The control presented here, a subclass of the Button control, demonstrates how client-side JavaScript code encapsulated in an ASP.NET server control can provide such functionality conveniently.

Though there are lots of JavaScript examples out there to accomplish this type of thing, I came across some issues when attempting to encapsulate this functionality in an ASP.NET control. My initial attempts involved disabling the button with a JavaScript onClick handler and substituting different text, but I found this would interfere with the functioning of the ASP.NET server-side Click event. What ultimately worked, providing better cross-browser support as well, was to have the button rendered within a <div> tag. This <div> can then be hidden without interfering with the ASP.NET Click event.

Using the control

As its descendent, the PleaseWaitButton functions just like a regular Button control. It exposes three additional properties to govern the display of the "Please Wait" message or image once the button is clicked.

  • PleaseWaitText
    This is the client-side text message to display, if any, in place of the button when clicked.
  • PleaseWaitImage
    This is the image file (typically an animated .gif) to display, if any, in place of the button when clicked. This property serves as the src attribute for the resulting <img> tag.
  • PleaseWaitType
    One of the PleaseWaitTypeEnum values – TextOnly, ImageOnly, TextThenImage, or ImageThenText – which governs the layout of the message and/or image.

Here is an example .aspx file demonstrating a PleaseWaitButton with both PleaseWaitText and PleaseWaitImage set:

<%@ Page language="C#" %>
<%@ Register TagPrefix="cc1" Namespace="JavaScriptControls" 
                             Assembly="PleaseWaitButton" %>

<script runat="server">
    private void PleaseWaitButton1_Click(object sender, System.EventArgs e)
    {
       // Server-side Click event handler; 
 
       // simulate something that could take a long time,
       // like a file upload or time-consuming server processing
 
       DateTime dt = DateTime.Now.AddSeconds(5);
       while (DateTime.Now < dt)
       {
         // do nothing; simulate a 5-second pause
       }
 
       // at the end of the loop display a success message
       // and hide the submit form 
       panelSuccess.Visible = true;
       PleaseWaitButton1.Visible = false;
    }
</script>
 
<html>
    <head>
        <title>Testing PleaseWaitButton</title>
    </head>
    <body>
        <form id="Form1" method="post" runat="server">
 
            <P>Testing the PleaseWaitButton control.</p>
 
            <cc1:PleaseWaitButton id="PleaseWaitButton1" runat="server" 
                     Text="Click me to start a time-consuming process"
                     PleaseWaitText="Please Wait... "
                     PleaseWaitImage="pleaseWait.gif" 
                     OnClick="PleaseWaitButton1_Click" />
 
            <asp:Panel id="panelSuccess" runat="server" 
                       visible="false">
                Thank you for submitting this form.  You are truly 
                the coolest user I've ever had the pleasure of serving.
                No, really, I mean it.  There have been others, sure,
                but you are really in a class by yourself.  
            </asp:Panel>
  
        </form>
    </body>
</html>

How it works

The PleaseWaitButton control renders a standard Button within a <div> tag. It also renders an initially empty <div> tag for the message/image.

protected override void Render(HtmlTextWriter output)
{
    // before rendering the button, output an empty <div>
    // that will be populated client-side via javascript
    // with a "please wait" message"
    output.Write(string.Format("<div id='pleaseWaitButtonDiv2_{0}'>", 
                  this.ClientID));
    output.Write("</div>");

    // render the button in an encapsulating <div> tag of its own
    output.Write(string.Format("<div id='pleaseWaitButtonDiv_{0}'>", 
                  this.ClientID));
    base.Render(output);
    output.Write("</div>");
}

These <div> tags are then manipulated through a client-side JavaScript onclick handler. The layout (text and/or image) and onclick assignment are made in the overridden OnPreRender method:

protected override void OnPreRender(EventArgs e)
{
    base.OnPreRender(e);

    // get the current onclick handler if any, and
    // set up the text message and/or image string
    // depending on the values of PleaseWaitText and
    // PleaseWaitImage
    string sCurrent = this.Attributes["onclick"];
    string sMessage = "";
    string sText = _pleaseWaitText;
    string sImage = (_pleaseWaitImage != String.Empty 
                     ? string.Format(
                        "<img src=/"{0}/" align=/"absmiddle/" alt=/"{1}/"/>"
                        , _pleaseWaitImage, _pleaseWaitText )
                     : String.Empty);

    // If we're using an image, register some javascript
    // for client-side image preloading
    if (sImage != String.Empty 
        && _pleaseWaitType != PleaseWaitTypeEnum.TextOnly)
            RegisterJavascriptPreloadImage(_pleaseWaitImage);
        
    // establish the layout based on PleaseWaitType
    switch (_pleaseWaitType)
    {
        case PleaseWaitTypeEnum.TextThenImage:
            sMessage = sText + sImage;
            break;
        case PleaseWaitTypeEnum.ImageThenText:
            sMessage = sImage + sText;
            break;
        case PleaseWaitTypeEnum.TextOnly:
            sMessage = sText;
            break;
        case PleaseWaitTypeEnum.ImageOnly:
            sMessage = sImage;
            break;
    }

    // Add the final code chunk as the javascript onclick handler
    string sCode 
        = string.Format(
    "PleaseWait('pleaseWaitButtonDiv_{0}', 'pleaseWaitButtonDiv2_{1}', '{2}');"
                      , this.ClientID, this.ClientID, sMessage);
    
    this.Attributes["onclick"] = sCode + sCurrent;
}

If a PleaseWaitImage is specified, the private method RegisterJavascriptPreloadImage() is executed. This outputs client-side code to preload the image. The registration key is based on the image name; if multiple buttons are used on a page with the same image, the preload script is rendered only once for the image.

private void RegisterJavascriptPreloadImage(string sImage)
{
    // javascript variable name for the image
    string sImgName = "img_" 
     + sImage.Replace(".","_").Replace("+", "_").Replace(" ", "_");

    // construct the client-side script to preload
    // the image
    StringBuilder sb = new StringBuilder();
    sb.Append("<script language='JavaScript'>");
    sb.AppendFormat("{0} = new Image();", sImgName);
    sb.AppendFormat("{0}.src = /"{1}/";", sImgName, sImage);
    sb.Append("</script>");

    // register the script with the page
    this.Page.RegisterClientScriptBlock(
        sImgName + "_PreloadScript", sb.ToString());
}

The embedded text file javascript.txt contains the client-side code to hide the button's <div> and display the "please wait" message/image. This code is loaded in the overridden OnInit() method with a call to the private method RegisterJavascriptFromResource(). This method calls the more generic method GetEmbeddedTextFile() which loads a text file embedded as a resource and returns the contents as a string.

protected override void OnInit(EventArgs e)
{
    base.OnInit(e);
    
    // the client-side javascript code is kept
    // in an embedded resource; load the script
    // and register it with the page.
    RegisterJavascriptFromResource();
}


private void RegisterJavascriptFromResource()
{   
    // load the embedded text file "javascript.txt"
    // and register its contents as client-side script
    string sScript = GetEmbeddedTextFile("javascript.txt");
    this.Page.RegisterClientScriptBlock("PleaseWaitButtonScript", sScript);
}


private string GetEmbeddedTextFile(string sTextFile)
{
    // generic function for retrieving the contents
    // of an embedded text file resource as a string

    // we'll get the executing assembly, and derive
    // the namespace using the first type in the assembly
    Assembly a = Assembly.GetExecutingAssembly();
    String sNamespace = a.GetTypes()[0].Namespace;

    // with the assembly and namespace, we'll get the
    // embedded resource as a stream
    Stream s = a.GetManifestResourceStream(
                string.Format("{0}.{1}", sNamespace, sTextFile)
            );
    
    // read the contents of the stream into a string
    StreamReader sr = new StreamReader(s);
    String sContents = sr.ReadToEnd();

    sr.Close();
    s.Close();

    return sContents;
}

The javascript.txt embedded resource contains the client-side method PleaseWait() which is executed in the JavaScript onclick handler for the button. This code calls the client method HideDiv() to hide the button's containing <div>, then populates the previously empty <div> tag with the message/image by setting its innerHTML property. The helper function GetDiv(), attempting to maintain cross-browser compatibility, inspects document.getElementById, document.all, and document.layers to return a <div> object given its id. The complete client-side code in javascript.txt follows:

<script language="JavaScript">
function GetDiv(sDiv)
{
    var div;
    if (document.getElementById)
        div = document.getElementById(sDiv);
    else if (document.all)
        div = eval("window." + sDiv);
    else if (document.layers)
        div = document.layers[sDiv];
    else
        div = null;

    return div;
}

function HideDiv(sDiv)
{
    d = GetDiv(sDiv);
    if (d)
    {
        if (document.layers) d.visibility = "hide";
        else d.style.visibility = "hidden";
    }
}

function PleaseWait(sDivButton, sDivMessage, sInnerHtml)
{
    HideDiv(sDivButton);
    var d = GetDiv(sDivMessage);
    if (d) d.innerHTML = sInnerHtml;
}
</script>

Summary

The ASP.NET server control PleaseWaitButton presented here renders a standard Button within <div> tags and companion client-side JavaScript to present users with a "please wait" message or image. Such a message can provide users with a useful visual cue for time-consuming form processing and prevent accidental multiple clicks.

About Mike Ellison


I work for the University of Nevada, Las Vegas in the Office of Institutional Analysis and Planning. Our office is charged with the mission of deriving useful information from institutional data. Within the context of that mission, my office mates and I apply technology in the form of custom data processing applications, data extraction and analysis tools, reporting tools, relational databases, OLAP solutions, data warehousing, and data mining.

Click here to view Mike Ellison's online profile.


Other popular ASP.NET articles:

【Claude Code · VibeCoding】11|需求梳理:云枢智学 / 学员平台 第三章 · 项目实战以「云枢智学」学员平台为例,把业务目标拆成可执行的需求条目。 阅读详情

相关推荐

centos+apache+subversion+LDAP

yum install subversion 报错:[Errno 14] HTTP Error 416 - Requested Range Not Satisfiable 正在尝试其它镜像。 zaici

qq_41566366的博客 1544

Android 5.1-手电筒应用小思路(三)

前面记录了两篇关于Android 4.4开发 Android手电筒小应用的一些心得,当然只是从上层来做一些简单的处理。     然而随着Android的发展和更新,Android Camera类已被标识为过时的类,官方建议开发者使用Camera2。在Android官方文档中也提到过(Android官方开发指南-Camera(相机)。 在Android5.1之前版本的SDK中,看不到androi

_风过丶花 2686

集成库仑计移动电源设计:从原理到实战,实现精准电量管理

在电池供电设备中,精准的电量计量是提升用户体验和产品可靠性的核心技术。传统基于电压估算的方法因受温度、负载和老化影响误差较大,而库仑计技术通过直接测量充放电电流并对时间积分,实现了电荷量的直接计量,从根本上提升了精度。这项技术的核心价值在于为设备提供了真实、可靠的电量状态数据,是智能电池管理系统的基础。其应用场景广泛,从消费电子如移动电源、智能穿戴,到工业与汽车领域如储能系统、新能源汽车的电池管理都不可或缺。本文以移动电源为例,深入解析了集成库仑计方案的硬件设计要点,特别是围绕高精度采样电阻与差分放大器的电

weixin_33453726的博客 548

Web 版翻译者资料库

本项目是桌面版《翻译者资料库》的 Web 移植版,基于 Spring Boot 3.3、Thymeleaf、Bootstrap 5.3 与 MySQL 8.0 构建。它面向翻译写作提供资料、词汇、句库、文本工具、对照制作、查找、备份恢复及旧库迁移等功能,完整继承桌面版核心业务规则,支持一键启动与离线访问。

howard2005的专栏 133

别再手动点按钮了!用C#给PowerMill做个自动化小助手(附完整源码)

本文详细介绍了如何使用C#进行PowerMill二次开发,打造自动化助手以提升CAM工程师的工作效率。通过实战案例和完整源码,展示了从环境配置到核心功能实现的完整流程,包括智能连接模块、项目批量处理器和刀路智能分析器等高级功能开发。

weixin_26899659的博客 344

YOLOv8轻量化模型瘦身术:深度解析与实战LAMP剪枝 YOLOv8(2021)

YOLOv8模型LAMP剪枝技术解析与实战 本文深入探讨了LAMP剪枝技术在YOLOv8目标检测模型中的应用。针对深度学习模型部署面临的资源限制问题,LAMP剪枝通过最小化L2失真和层自适应稀疏度分配,实现了高效模型压缩。相比传统幅度剪枝的"一刀切"方法,LAMP创新性地将剪枝建模为优化问题,定义LAMP分数来衡量权重重要性,自动确定各层最佳剪枝率。文章从理论基础出发,详细解析了LAMP的核心数学公式和算法流程,并提供了完整的YOLOv8移植实战指南,包括代码结构、剪枝步骤和微调策略。通

FJN110的博客 2422

React 性能:memo / useMemo / useCallback

讲清 memo/useMemo/useCallback 的配合与边界,先测量再优化,避开常见过早优化。

JudithHuang的博客 325

基于YOLOv10的微小目标检测,多头检测器提升小目标检测精度

引入多头检测器助力YOLOv10,暴力提升小目标检测性能

①答疑群聊服务;②YOLO大模型知识问答系统;③计算机视觉论文生成智能体; 2569

V8 机制、手写核心函数与 TypeScript 类型体操

或固定初始化(如数组先定长、对象先给全字段)保持类型与形状稳定;这些都比"换框架"更基础。只能处理纯数据(丢函数、Date、RegExp、循环引用报错)。生产级深拷贝要处理:原始值短路、循环引用、V8(Chrome / Node 的 JS 引擎)不是"解释一行跑一行"那么简单,它用。图:V8 执行流程——解释执行 + 热点优化,优化失败会 Deopt 回退。JS 内存自动管理,但"自动"不等于"不会漏"。是"固定间隔最多执行一次"。手写 Promise 是"懂异步"的试金石。是"停下后才执行最后一次",

qq_38468358的博客 333

IEC61850规约客户端软件开发实战(第六章)

IEC 61850标准中的GOOSE(Generic Object Oriented Substation Event,面向通用对象的变电站事件)功能是变电站自动化系统的核心通信机制,主要用于实现智能电子设备(IED)间高可靠性、低延时的实时信号传输。本章简述其核心功能与技术特点。

半青年的博客 1778

SKUA-GOCAD入门教程-第六节

DisplayElements窗口是用于浏览和处理项目数据的工具,包含多个数据浏览器,如模型列表、对象、未分类对象、属性数据及资源数据。

江洋大葱的博客 983

DSH (DeepSeek Harness) Windows 升级安装指南20261107

注意:如果在普通窗口执行 nvm 提示找不到命令,或执行 nvm use 提示 Access is denied,请务必关闭当前窗口,重新打开一个管理员CMD 执行上述完整路径命令。找到 .credentials.yaml,将其重命名为 .credentials.yaml.bak(备份并使其失效)。Node.js Storage Location:可改到非系统盘(如 D:\dev\nvm,避免路径含空格或中文)。打开文件资源管理器,进入 C:\Users<你的用户名>.dsh\。

fengye207161的博客 185

ardupilot开发 --- Remote ID 篇

适配ardupilot的Remote ID模块研发,远程标识模块研发。Remote ID模块可以通过蓝牙或wifi向外广播无人机的状态信息、位置信息、任务信息等,并可以通过蜂窝数据向国家无人驾驶航空器一体化综合监管服务平台上报这些信息。Remote ID功能是21年起国家出台的民用无人机适航飞行的基本要求!

记录老板的每次pua,分享领导每天的毒鸡汤... 9607

SpringBoot「衣依」服装销售平台:144个Java文件180个接口,从挑衣服到收货评价整条链路都在

# SpringBoot「衣依」服装销售平台:144个Java文件180个接口,从挑衣服到收货评价整条链路都在 > 这是一套基于 Spring Boot 的服装销售平台源码,配套 `db.sql` 建表脚本,业务覆盖商品展示、购物车、订单流转、收货地址、订单评价、商品评论、在线客服、轮播图和资讯。形态是**前后台双端**:前台是顾客逛的商城,后台是管理员管的控制台。本文带你看清里面有什么、怎么跑

面朝大海 225

jdk-8u144-linux-x64.tar.gz.

该资源为搭建Linux系统Java环境用,资源的后缀为tar.gz格式的压缩包

Outlook Express 6 (OE6) for Win7/Win8/Win10

英文版 Outlook Express6.0, 兼容Win7/Win10/WinXP,解压就可用。

微信小程序-wxs

在微信开发者工具中右键创建.wxs后缀的文件。每个.wxs文件也是一个独立模块,同样使用导出内容。示例(文件return d;FOO: foo,bar: bar(外联定义参考官方文档)

dreams_dream的博客 335

大中型超市收银系统(可直接运行)

光步前台收银系统系统功能:商品销售、商品退货、挂单、收银员权限、会员销售、单品取消、整单取消、商品查询、脱机销售、脱机数据上传,基本资料下载,开钱箱、小票打印、收款结算,支持多币种付款方式(现金、储值卡、礼券、微信等),支持多种促销。运行环境:.net 4.0登陆信息用户名:1001 密码:123456内置商品信息,商品编码可输入00001000 - 00010000,测试效果相关功能键F5 结算 F9挂单 F11商品查询 F8退货 Insert单品取消 Del整单取消 F12开钱箱F2 会员 Ctrl+Z退出系统 Home 锁屏 相关源码待公开

使用echarts模拟甘特图

项目中需按时间段展示不同颜色的数据,通过解析时长并统计各类型总时长,结合预设颜色映射表(含自定义与默认色),动态生成ECharts图表。利用sumByTypeName聚合数据,为每类分配对应颜色,实现图例与柱状图的精准匹配,确保多时段、多类型数据可视化清晰准确。

uuai 28

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

【技术专题】JavaScript 网页技术 - JavaScript 流程控制

小锋老师推出《一天学会JavaScript(无废话版)》视频教程,涵盖基础语法、流程控制、函数、数组对象、DOM操作及ES6新特性。内容精炼,配套课件与源码打包下载,助力快速入门。重点讲解if/else、switch、for/while循环、for...of/in遍历及break/continue使用场景,并通过成绩判断实例演示实际应用。适合零基础学习者高效掌握核心技能。

java1234的博客 158

Agent 的 ReAct、Plan、Execute、Reflection 模式

本文系统解析 Agent 的 ReAct、Plan、Execute、Reflection 四模式,揭示其核心为“下一步谁定”与“错了怎么发现”两大问题。ReAct 逐步决策,适合动态环境但易冗余;Plan 一次性规划,高效却惧变化;Execute 严格落地,需明确判据与失败策略;Reflection 事后校验,强化纠错闭环。四者协同:外层规划,执行中嵌入思考,每步后反思,连续失败才重规划,构建稳定可控的智能体工作流。

2401_89855466的博客 324

基于 FastAPI+LangChain+LangGraph+Agent+Vue3+MySQL 的房产数据采集与房价预测分析平台

本文介绍一个完整的「房产数据采集+AI房价预测」全栈项目,涵盖FastAPI异步后端、LangGraph Agent智能问答、爬虫采集、机器学习预测与Vue3前端,实现从数据采集到AI交互的闭环。项目融合多技术栈,具备真实业务场景与生产级设计(如降级策略、流式输出、多模型对比),兼具简历亮点与答辩演示优势,可系统性提升工程能力,并附高频面试题解析,是理想的技术综合实践项目。

深耕开发,专注编程实战。分享源码解析、项目搭建、问题排查笔记,沉淀技术,持续更新。 225

货运APP、货运小程序开发:网络货运平台与同城配送搬家系统实战

本文介绍一套完整的货运平台系统,涵盖货运APP、小程序、网络货运、同城配送、搬家预约等场景,基于SpringBoot+MyBatisPlus+MySQL技术栈,采用uni-app实现多端统一开发,配套TMS运输管理与物流管理系统,支持下单、派单、运输、结算全流程,适用于货运搬家、物流搬运与配送业务,可作为物流软件及TMS系统的参考实现。

juzige03的博客 217

Vue3 低代码移动表单设计器实战(二):缩放画布下的拖拽系统与树状级联数据结构

本文深入剖析Vue3低代码表单设计器在缩放画布下的拖拽失效问题,揭示SortableJS在CSS Transform下坐标崩溃的数学根源。通过自研独立视觉克隆壳层与逆向几何补偿算法,实现精准拖拽;采用扁平数据存储+运行时树状计算结构,解决级联依赖与深克隆难题,确保逻辑一致性与性能优化,为复杂低代码系统提供可复用的工程范式。

NanChen的博客 340

Vue-Router

本文详解前端路由原理与实现,以网易云音乐为例,介绍通过 vue-router 实现页面无刷新切换。核心步骤包括:安装模块、创建路由实例、注册应用、配置页面组件与路由出口。使用 router-link 实现声明式导航,结合 query 和 params 传参,支持模糊与精确匹配激活状态。强调 useRoute(读取参数)与 useRouter(执行跳转)的区别,帮助开发者掌握单页应用路由的核心机制。

2301_79245606的博客 339

LangGraph == 循环结构的实现

这是静态约束,不会参与运行时校验。主要作用是提升代码可读性、通过静态类型检查,同时帮助 LangGraph。也就是说,是否继续重试,在当前实现中主要由大模型决定,而不是由程序逻辑强制保证。因此,如果模型在多次工具调用失败后选择停止重试并生成最终回答,运行图不会阻止它。函数,也不再需要调用 add_conditional_edges()只要大模型持续返回工具调用,流程就会不断回到 llm_node。的缩写,即“推理 + 行动”架构。,运行时只负责判断具体走哪一条路径。

每天都要努力学习哦~~ 347

Vue 前端开发 AI 对话页面:流式消息渲染、文件上传

关键点是不能手动设置 Content-Type 为 multipart/form-data,必须由浏览器自动生成带有 boundary 的请求头,否则后端无法解析。思路:将对象序列化为 JSON 字符串,作为 FormData 的一个普通字段(如 formData.append(‘payload’, JSON.stringify(data))),后端接收该字段后再反序列化。若上传大文件(>10MB),需实现独立的分片上传接口,在提交对话前先获取文件 id 或 url,再随文本发送引用。移除输入框的禁用态;

2402_85729970的博客 385

Flux 架构:一个单向数据流库是怎么跑起来的

状态只有一份 + 数据单向流 + reducer 是纯函数 + 中间件链可组合 + 视图层声明式绑定。这 30 行就是这套思想的最小完整样本:两次useStore订阅、一次拿链式 dispatch、四个按钮对应四种 action(其中一种是 thunk 形态)。

sun_weitao的博客 108
上一篇: Client Callbacks in ASP.NET 2.0
下一篇: Enhanced List Box Control
colderboy
博客等级 码龄26年 1粉丝 3原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值