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
Post a Comment