如果文本框名称在字符串变量中,如何获得clientID

时间:2021-07-10 11:13:37

I have written below code to check for blank value in my textbox but its generating compilation Error, please provide me solution.

我写了下面的代码来检查我的文本框中的空白值,但是它生成的编译错误,请提供给我解决方案。

my code in javascript:

我在javascript代码:

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

error:

错误:

'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?)

I am calling it like this : checkTextboxNotFilled("MytextboxName")

我这样调用它:checkTextboxNotFilled(“MytextboxName”)

1 个解决方案

#1


3  

This may be helpful to you.

这可能对你有帮助。

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

and call : checkTextboxNotFilled("<%= Mytextbox.ClientID %>");

并调用:checkTextboxNotFilled(“<%= Mytextbox”)。ClientID % >”);

#1


3  

This may be helpful to you.

这可能对你有帮助。

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

and call : checkTextboxNotFilled("<%= Mytextbox.ClientID %>");

并调用:checkTextboxNotFilled(“<%= Mytextbox”)。ClientID % >”);