2011年5月12日 星期四

.net button

使用者在操作網頁過程中
常會不耐煩而多次點擊按鈕
為了不讓使用者一直點擊送出
通常會在點擊後使按鈕設為disabled
<asp:Button … onclientclick="this.disabled=true;">
但是這在.net中會造成連submit的動作也取消掉
    解決的方法有二
  1. 在onclick事件中加入
    Button1.Attributes["onclick"] = "this.disabled=true;" + this.Page.ClientScript.GetPostBackEventReference(button1, "");

  2. 在button標籤中加入
    <asp:Button … onclientclick="this.disabled=true;" UseSubmitBehavior="false"


參考網址內還有另一種解決方法
--
參考網址
http://gogo1119.pixnet.net/blog/post/29176264
http://tw.myblog.yahoo.com/frankintaiwan/article?mid=1095

沒有留言:

張貼留言