I'm a newbie so please forgive me if this is a stupid question. I don't understand what I've missed in the code below and how I can get it to work.

I have a few lines of code that works fine. It makes a * show as an error message next to an empty required field:

if (String.IsNullOrEmpty(TextBoxFirstName.Text))
                TxtFirstNameReq.Visibility = Visibility.Visible;
            else
                TxtFirstNameReq.Visibility = Visibility.Collapsed;

but it seems I can't add a line of code like this. I want to show a explanation "*=required field" every time the error message above shows:

if (String.IsNullOrEmpty(TextBoxFirstName.Text))
                TxtFirstNameReq.Visibility = Visibility.Visible;
                TxtReqField.Visibility = Visibility.Visible;
            else
                TxtFirstNameReq.Visibility = Visibility.Collapsed;

Error messages:
Line 3 on ';' - "Only assignment, call, increment, decrement, and new object expressions can be used as a statement"
Line 4 - "Invalid expression term 'else'", and "; expected"

Thankful for any help!

You are missing the {} around the first part of the if statement.

You are missing the {} around the first part of the if statement.

That's it! Ok, so I need the brackets if there are more than one line of code after an if, but not if there's only one line of code?
Thanks!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.