2010-06-30 6 views
3

텍스트 상자에 빈 값이 있는지 확인하기 위해 아래 코드를 작성했지만 컴파일을 생성하는 동안 오류가 발생했습니다. 솔루션을 제공해주십시오. 자바 스크립트텍스트 상자 이름이 문자열 변수 인 경우 clientID를 얻는 방법

내 코드 :

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

감사 브로, 그것의 현재 작업. 하지만 textbox 이름이 문자열 형식 인 경우 clientid를 얻는 방법은 무엇입니까? –

+0

아니요. 그렇게하면 오류가 발생합니다. 나는 너만이 길로 가야한다고 생각해. – Krunal

+0

좋아, 고마워. .. –

관련 문제