*********怎樣使點擊button一次就計數一次,因為......
怎樣使點擊button一次就計數一次,因為有user看到點擊button後反應很忙,就又再點擊,到後來,代碼就會執行好幾次?
怎麼下面這樣不行呢?
private int i=0;
public void btnOKHandle(object sender,EventArgs e)
{
i++;
Response.Write(i);
}
謝謝大家!
[解决办法]
hidefield
[解决办法]
private int i=0;
public void btnOKHandle(object sender,EventArgs e)
{
if(ViewState[ "Count "] != null)
{
ViewState[ "Count "] = i;
}
else
{
ViewState[ "Count "] = (int)ViewState[ "Count "] + 1;
}
}
[解决办法]
private int iCount { get { if (ViewState[ "iCount "] != null) { return (int)ViewState[ "iCount "]; } else return 0; } set { ViewState[ "iCount "] = value; } }Button_Clickthis.iCount ++;
[解决办法]
每次提交页面,这个page类重新被实例化.
[解决办法]
private int i=0;
每次 i都被重新實例化為0
所有你永遠只能得到1
[解决办法]
点后用js把那个button disabled
[解决办法]
PageLoad里加上这一行:
ButtonID.Attributes.Add( "onclick ", @ "JavaScript:this.disabled=true; ");
//ButtonID是你的Button的Id
[解决办法]
完美解决方案:
aspx中添加JS脚本:
<script type= "text/javascript ">
var x = 0;
function xx()
{
x++;
if(x==1)
{
return true;
}
else
{
return false;
}
}
</script>
///CS的PageLoad中添加:
YourButton.Attributes.Add( "onclick ", @ "JavaScript:return xx(); ");