views:

38

answers:

2

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:

 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")

+5  A: 

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 %>");

Krunal
Thanks Bro, Its working now. but is their any way to get clientid if textbox name is in string format..?
Rajesh Rolen- DotNet Developer
Nope. That way you will get the error. I think you should go this way only.
Krunal
ok, thanks a lot..
Rajesh Rolen- DotNet Developer
A: 

try using find method on control collection it might be helpful

Neo