Assigned value to a label of a ASP.NET web form if field is left blank?

I am using Visual Studio 2019 to make a Web Form with labels that allow user entry. How do I detect that a field is left blank and then assigned a value “0” to that label?

Assuming your field is called myField and your label is called myLabel you can do something like this…

if (myField.text == string.Empty) {
   myLabel.text = "0";

Alternatively you can use the String.IsNullOrEmpty() or String.IsNullOrWhiteSpace() functions on the myField.text value.

If the text field and the label are actually the same element, then you can just check if it is empty like shown above and then set the myField.text = "0"

But you get the idea I am sure. :slight_smile: