2010-06-30 24 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