asp.net避免按钮重复点击,使按钮点击后变灰

来源:互联网 发布:蜂群算法的优点 编辑:程序博客网 时间:2024/05/01 03:04

按钮ID为:btnSubmit

为实现rt功能,只需要添加两句代码即可。

1. 在.aspx页面第一行<%@ Page %>中添加:

EnableEventValidation="false"

 

2. 在服务端代码的Page_Load方法中添加如下代码:

//使按钮不可用并回调服务端事件

this.btnSubmit.Attributes.Add("onclick", ClientScript.GetPostBackEventReference(btnSubmit, "Click"+ ";this.disabled=true; this.value='提交中...';");

 

提供网上其他人写的一个简单示例:

//使按钮不可用并回调服务端事件
 protected void Page_Load(object sender, EventArgs e)
{
   this.btnOK.Attributes.Add("onclick", ClientScript.GetPostBackEventReference(btnOK, "Click"+ ";this.disabled=true; this.value='提交中...';");

 }

 

//按钮处理方法

protected void btnOK_Click(object sender, EventArgs e)

{
  System.Threading.Thread.Sleep(2000);
  ClientScript.RegisterStartupScript(GetType(), "btnCommit""alert('提交成功!!!');",  true);

 }

原创粉丝点击