日期:2014-05-19  浏览次数:20566 次

|G|禁止按钮点2次的问题!在网速很慢时,误点两次,怎么处理?
希望帮帮忙!
因为有些只能点击一次!我做了个简单实例!
public   partial   class   _Default   :   System.Web.UI.Page  
{
        public   static     int   i   =   10;
        public   static     int   j   =   10;
        protected   void   Page_Load(object   sender,   EventArgs   e)
        {

        }
        protected   void   Button1_Click(object   sender,   EventArgs   e)
        {
                i--;
                Response.Write(i.ToString());
        }
        protected   void   Button2_Click(object   sender,   EventArgs   e)
        {
                Button2.Enabled   =   false;
                i--;
                Response.Write(i.ToString());
        }
}
-----------
-----------
1.但是调试的时候,无论我多么快的点2次,click只执行一次!
2.Button2的这种写法,能不能保证无论网速多么慢,按钮不会点击2次!

------解决方案--------------------
使用button按钮 不要 使用 服务器按钮和submit按钮

<input id= "Button1 " type= "button " onclick= "this.disabled=true; " value= "提交 " onserverclick= "Button1_ServerClick " runat= "server " />


.cs 执行完你的操作后

Page.RegisterStartupScript( "enBtn ", " <script> document.getElementById( 'Button1 ').disabled=false; </script> ");
------解决方案--------------------
if (!this.IsPostBack) { Session[ "CanClick "] = true; } protected void Button1_Click(object sender, EventArgs e) { if ((bool)Session[ "CanClick "]) { //do something Session[ "CanClick "] = false; } else { Response.Write( "不可多次点击! "); } }
------解决方案--------------------
SESSION记录点的次数
------解决方案--------------------
在客户端做,点击按钮后用javascript把按钮状态设为不可用就可以
<asp:Button ID= "Button1 " runat= "server " Text= "Button " OnClientClick= "this.disabled=true;return true; " OnClick= "Button1_Click " />
========
说这种话的人不负责任,自己根本没试过,LZ,给你一份自定义控件的代码,自己编译成控件就可以实现了
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel;
using System.Drawing;
namespace gunion.Utility
{

/**/
/// <summary>
/// 显示BUTTON控件,让控件只能按一次
/// </summary>
public class OneClickButton : System.Web.UI.WebControls.Button
{
private string waitText = "请稍等正在提交 ";
private string warningText = "确定保存吗?(Yes/No) ";
private bool _ShowMessageBox = true;
private Color BgColor;
private CurSor _Cursor = CurSor.auto;

public enum CurSor
{
hand = 0,
text = 1,
wait = 2,