2011-07-22 24 views
2

我有一個asp:dropdownlist,onchange事件我已經調用了一些JavaScript,我啓用和禁用某些必需的字段驗證器,一旦RFV得到啓用它顯示附加到它的錯誤味精.. !!!!!!!! ...必要的字段驗證器啓用時,其啓用的屬性設置爲true通過javascript

我希望它只啓用不顯示錯誤味精在它被啓用時....

上提交單擊它應該顯示味精...

和Javascript:

function CriteriaChange(ddlCType) 
{ 
    switch (ddlCType.value) 
    { 
     case "1": //Weightage 
      ValidatorEnable(document.getElementById('<%= rfvWeightage1.ClientID %>'), true); 
      break; 

     case "2": //Any One 
      ValidatorEnable(document.getElementById('<%= rfvAppraiser.ClientID %>'), true); 
      break; 

    } 
} 
+0

也許會的CustomValidator是一個更好的選擇嗎? –

+0

Offcource我有很多選擇兄弟..但它是最簡單的一個,它不工作... yyyyy ....? – Tami

回答

0

試試這個...

function CriteriaChange(ddlCType) {  
    switch (ddlCType.value)  
    {  
     case "1": //Weightage    
      // ValidatorEnable(document.getElementById('<%= rfvWeightage1.ClientID %>'), true); 
      document.getElementById('<%= rfvWeightage1.ClientID %>').enabled = true; 
      document.getElementById('<%= rfvAppraiser.ClientID %>').enabled = false; 
      break; 
     case "2": //Any One    
      //ValidatorEnable(document.getElementById('<%= rfvAppraiser.ClientID %>'), true); 
      document.getElementById('<%= rfvAppraiser.ClientID %>').enabled = true; 
      document.getElementById('<%= rfvWeightage1.ClientID %>').enabled = false; 
      break; 
    } 
} 

注:我一往直前,把它禁用其他驗證的情況下,他們交換價值來回所以他們不都得到在同一時間啓用。

希望這會有所幫助。

2

由於visibility CSS樣式是在驗證器調用Validator時切換的樣式,您可以在啓用驗證器後立即設置此樣式。驗證事件在提交時仍然會被再次調用,所以它會覆蓋此設置,以便在表單提交時顯示驗證器。

function CriteriaChange(ddlCType) 
{ 
    var val = null; 
    switch (ddlCType.value) 
    { 
     case "1": //Weightage 
      val = document.getElementById('<%= rfvWeightage1.ClientID %>'); 
      break; 

     case "2": //Any One 
      val = document.getElementById('<%= rfvAppraiser.ClientID %>'); 
      break; 
    } 
    if (val != null) 
    { 
     ValidatorEnable(val, true); 
     val.style.visibility = 'hidden'; // or collapse, if you prefer 
    } 
} 
相關問題