在按钮点击后禁用它直到操作完成(利用线程休息)

本文展示了一个使用ASP.NET 2.0以上版本实现的网页交互实例,通过按钮、链接按钮和图片按钮触发事件,展示当前时间并计数。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

<%@ Page Language="C#" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><script runat="server">protected void Page_Load (object sender, EventArgs e){btn.Attributes.Add ("onclick",Page.GetPostBackEventReference (btn, "") +";this.value='Submitting';this.disabled = true;");lbtn.Attributes.Add ("onclick","this.innerText='Submitting';this.disabled = true;");ibtn.Attributes.Add ("onclick",Page.GetPostBackEventReference (ibtn, "") +";this.alt='Submitting';this.disabled = true;");// // ASP.NET 2.0 above // //btn.Attributes.Add ("onclick", // ClientScript.GetPostBackEventReference (btn, "") + // ";this.value='Submitting';this.disabled = true;"); //lbtn.Attributes.Add ("onclick", // "this.innerText='Submitting';this.disabled = true;"); //ibtn.Attributes.Add ("onclick", // ClientScript.GetPostBackEventReference (ibtn, "") + // ";this.alt='Submitting';this.disabled = true;"); // // OR // //btn.OnClientClick = // ClientScript.GetPostBackEventReference (btn, "") + // ";this.value='Submitting';this.disabled = true;"; //lbtn.OnClientClick = "this.innerText='Submitting';this.disabled = true;"; //ibtn.OnClientClick = ClientScript.GetPostBackEventReference (ibtn, "") + // ";this.alt='Submitting';this.disabled = true;"; }protected void btn_Click (object sender, EventArgs e){System.Threading.Thread.Sleep (2000);Label1.Text = DateTime.Now.ToString ();}protected void lbtn_Click (object sender, EventArgs e){LinkButtonClickCount++;System.Threading.Thread.Sleep (2000);Label1.Text = "link button:" + DateTime.Now.ToString ()+ "<br/>count:" + LinkButtonClickCount.ToString ();}protected void ibtn_Click (object sender, ImageClickEventArgs e){ImageButtonClickCount++;System.Threading.Thread.Sleep (2000);Label1.Text = "image button:" + DateTime.Now.ToString ()+ "<br/>count:" + ImageButtonClickCount.ToString ();}int LinkButtonClickCount{get{object tmp = ViewState["LinkButtonClickCount"];return (tmp == null) ? 0 : (int)tmp;}set { ViewState["LinkButtonClickCount"] = value; }}int ImageButtonClickCount{get{object tmp = ViewState["ImageButtonClickCount"];return (tmp == null) ? 0 : (int)tmp;}set { ViewState["ImageButtonClickCount"] = value; }}</script><html xmlns="http://www.w3.org/1999/xhtml"><head runat="server"><title>无标题页</title></head><body><form id="form1" runat="server"><div><asp:Button ID="btn" runat="server" Text="What time is it, please!"OnClick="btn_Click" /><asp:LinkButton ID="lbtn" runat="server" OnClick="lbtn_Click">What time is it, please!</asp:LinkButton><asp:ImageButton ID="ibtn" runat="server"AlternateText="What time is it, please!"Height="30px" OnClick="ibtn_Click"ImageUrl="http://www.ikea.com/ms/img/menu/products/32x32/clocks_32x32.gif"/><br /><asp:Label ID="Label1" runat="server" Text=""></asp:Label></div></form></body></html>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值