c# - Disabling a button if textbox is empty -


hey guys have quick , easy question guess you. want find out if can create real time event check value of textbox. mean if textbox empty button wouldnt clickable. im thinking there anyway apart validation in code? far im stuck here:

if (yourname.text = null) {        submitbutton.enabled = "false"; } 

where yourname textbox , submitbutton button :)

system.string provides pair of convenient functions called isnullorempty , isnullorwhitespace can use testing kinds of strings empty end users:

if (string.isnullorwhitespace(yourname.text)) {     submitbutton.enabled = false; // <<== no double-quotes around false } else {     // don't forget re-enable button     submitbutton.enabled = true; } 

this disable button string composed entirely of blank characters, makes sense when validate name.

the above identical to

submitbutton.enabled = !string.isnullorwhitespace(yourname.text); 

which shorter version if.


Comments

Popular posts from this blog

php - Why I am getting the Error "Commands out of sync; you can't run this command now" -

linux - Does gcc have any options to add version info in ELF binary file? -

java - Are there any classes that implement javax.persistence.Parameter<T>? -