服务器速度太慢,经常有用户等不及多次点击按钮,我希望用户点击按钮一次后把该按钮禁用,以免重复点击。我想到3种办法:
1、在前台document.getElementById("btnSave").disabled='disabled',按钮禁用了,可也不向服务器发送信息了。
2、在后台禁用,可要服务器执行之后才有效,不符合要求。
大家有什么好办法吗?

解决方案 »

  1.   


    string script = ClientScript.GetPostBackEventReference(this.Button_OK, null);
    if (!Page.IsPostBack)
    {
        System.Text.StringBuilder sb = new System.Text.StringBuilder();
        sb.Append("window.document.getElementById(’" + this.Button_OK.ClientID + "’).disabled = true;");
        sb.Append(script);
        sb.Append(";");
        this.Button_OK.Attributes.Add("onclick", sb.ToString());
    }
      

  2.   

    string script = ClientScript.GetPostBackEventReference(this.Button_OK, null);
    if (!Page.IsPostBack)
    {
        System.Text.StringBuilder sb = new System.Text.StringBuilder();
        sb.Append("window.document.getElementById(’" + this.Button_OK.ClientID + "’).disabled = true;");
        sb.Append(script);
        sb.Append(";");
        this.Button_OK.Attributes.Add("onclick", sb.ToString());
    }GetPostBackEventReference会生成html代码:<script type="text/javascript">
    <!–
    var theForm = document.forms[’form1′];
    if (!theForm) 
    {
        theForm = document.form1;
    }
    function __doPostBack(eventTarget, eventArgument) {
        if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
            theForm.__EVENTTARGET.value = eventTarget;
            theForm.__EVENTARGUMENT.value = eventArgument;
            theForm.submit();
        }
    }
    // –>
    </script>
    生成的script值为__doPostBack(’Button_OK’,'’)
      

  3.   

    <asp:Button runat="server" ID="BtnSubmit" 
      OnClientClick="this.disabled = true;" 
      UseSubmitBehavior="false" 
      OnClick="BtnSubmit_Click" 
      Text="Submit" />
      

  4.   


    document.getElementById("btnSave").disabled='disabled'就行了。简单的问题无须搞到服务端执行
      

  5.   

    http://www.cnblogs.com/freexiaoyu/archive/2008/11/21/1338545.html
      

  6.   


    js 的感觉可行如果你放到后台设置visbale那肯定不行;一遇到网络延迟说不好就入好几条记录;如果你用后台的话建议你用存储过程 ,
      

  7.   

    if(!isPostBack)
    {
        this.Btn.Enable=true;
    }else{
         this.Btn.Enable=false;}