How to get client id if text field name is in string variable

I wrote the code below to check for an empty value in my text box, but its compilation generation failed, please provide me a solution.

my javascript code is:

 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 call it like this: checkTextboxNotFilled ("MytextboxName")

+3
source share
1 answer

This may be useful for you.

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

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

+3
source

Source: https://habr.com/ru/post/1752395/


All Articles