2010-06-30 22 views
3

我寫下面的代碼來檢查我的文本框中的空白值,但它的生成編譯錯誤,請爲我提供解決方案。如何獲取clientID如果文本框名稱是字符串變量

我的代碼在javascript:

function checkTextboxNotFilled(txtbox) { 
     var txtb = document.getElementById("<%= " + txtbox + ".ClientID %>"); 
     if (GetFormattedString(txtb.value) == "") { 
      return true ; 
     } 
     else { 
      return false ; 
     } 
    } 

錯誤:

'string' does not contain a definition for 'ClientID' and no extension method 'ClientID' accepting a first argument of type 'string' could be found (are you missing a using directive or an assembly reference?) 

我打電話這樣的:checkTextboxNotFilled( 「MytextboxName」)

回答

3

這可能會對你有所幫助。

function checkTextboxNotFilled(txtboxid) { 
     var txtb = document.getElementById(txtboxid); 
     if (GetFormattedString(txtb.value) == "") { 
      return true ; 
     } 
     else { 
      return false ; 
     } 
    } 

,並呼籲:checkTextboxNotFilled("<%= Mytextbox.ClientID %>");

+0

感謝兄弟,它現在的工作。但是他們的任何方式來獲得clientid如果文本框名稱是字符串格式..? – 2010-06-30 06:16:31

+0

沒有。這樣你會得到錯誤。我認爲你只能這樣做。 – Krunal 2010-06-30 06:17:54

+0

好的,非常感謝.. – 2010-06-30 06:33:54