Muhammed Salah Muhammed Salah - 1 month ago 10
C# Question

How to check if a MaskedTextBox is empty from a user input?

I'm using a

MaskedTextBox
, with the following short date
Mask
: "00/00/0000".

My problem is that I wanna know when the control is empty:

if (string.IsNullOrEmpty(maskedTextBox1.Text))
{
DataTable dt = function.ViewOrders(Functions.GetEid);
dataGridView2.DataSource = dt;
}


It's not working, when
maskedTextBox1
looks empty (and I'm sure it is), the
if
statement doesn't detect that it is
null
or
Empty
.

Answer

You can simply use:

maskedTextBox1.MaskCompleted

Or

maskedTextBox1.MaskFull

properties to check if user has entered the complete mask input or not.