2014-03-27 28 views
0

我想啓用一個功能,無論您何時點擊一個圖像按鈕,它都會自動切換到一個加載圖像,該圖像也禁用它,因此用戶無法多次點擊它直到它完成它的過程。在ASP.NET C#上篡改ImageButton後保留原始屬性

我做到以下幾點:

protected void Page_Load(object sender, EventArgs e) 
    { 
     ibtnCancel.Attributes.Add("onclick", DisableButton(ibtnCancel)); 
     ibtnSave.Attributes.Add("onclick", DisableButton(ibtnSave)); 
    } 


protected string DisableButton(ImageButton objImageButton) 
     { 
      string strAttribute = GetScript(); 
      strAttribute += "this.value = 'PROCESSING...';"; 
      strAttribute += "document.getElementById('" + objImageButton.ID + "').disabled = true;"; 
      strAttribute += "document.getElementById('" + objImageButton.ID + "').src = '../images/saveInactive.png';"; 
      strAttribute += Page.GetPostBackEventReference(objImageButton) + ";"; 

      return strAttribute; 
     } 

然而,我注意到,一些網頁表單中指定的屬性是不再工作,例如:

<asp:ImageButton ID="ibtnCancel" runat="server" ImageUrl="~/images/cancelar.png" CausesValidation="False" onclick="ibtnCancel_Click" /> 

的CausesValidation是不再有效,所以這意味着如果在表單上有一個驗證器會被觸發,當我點擊這個按鈕時,儘管我試圖告訴它不會,但是它會出現。

我該如何解決這個問題?,我可以在指定的方法上編輯任何東西?

回答