Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6916935
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T09:40:00+00:00 2026-05-27T09:40:00+00:00

What is the right way to do this? This way is not working: if

  • 0

What is the right way to do this? This way is not working:

if (((String)enterAmountButton.Content) == "")
 MessageBox.Show("Please enter the total bill amount.");
else if (((String)enterTipButton.Content) == "")
 MessageBox.Show("Please enter the tip % amount.");   

this way is not working neither:

if (enterAmountButton.Content == "")   
 MessageBox.Show("Please enter the total bill amount.");   
else if (enterTipButton.Content == "")   
 MessageBox.Show("Please enter the tip % amount.");   
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T09:40:00+00:00Added an answer on May 27, 2026 at 9:40 am
    var amountButtonString = enterAmountButton.Content as string;
            var enterTipButtonString = enterTipButton.Content as string;
            if (String.IsNullOrEmpty(amountButtonString))
                MessageBox.Show("Please enter the total bill amount.");
            else if (String.IsNullOrEmpty(enterTipButtonString))
                MessageBox.Show("Please enter the tip % amount.");  
    

    would work. However, how are you expecting to get the strings? you most likely want the value in a TextBox that is next to the button, correct?

    in that case:

    if (String.IsNullOrEmpty(amountTextBox.Text))
                    MessageBox.Show("Please enter the total bill amount.");
                else if (String.IsNullOrEmpty(tipTextBox.Text))
                    MessageBox.Show("Please enter the tip % amount.");  
    

    where amountTextBox & tipTextBox are the x:Name of your TextBoxes.

    One last thing:

    There’s probably a better way to handle this. For example, if you handle the KeyUp & TextChanged events on the TextBoxes and only Enable the button when text exists (even better, valid text ;))

    You could use a converter too:

    public class StringToEnabledConverter : IValueConverter
        {
            #region IValueConverter Members
    
            public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
            {
                var val = value as string;
                if (val == null)
                    throw new ArgumentException("value must be a string.");
    
                return !string.IsNullOrEmpty(val);
            }
    
            public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
            {
                throw new NotImplementedException();
            }
    
            #endregion
        }
    

    Add a reference to your converter <Converters:StringToEnabledConverter x:Key="StringToEnabledConverter" />

    and on your button,

    <TextBox x:Name="amountTextBox />
    <Button x:Name="enterAmountButton" Enabled="{Binding ElementName=amountTextBox, Path=Text, Converter={StaticResource StringToEnabledConverter}}" />
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Sorry, I'm not really sure of the right way to ask this one so
Not very sure if this is the right way of asking, but I was
Hi I am not sure if this is the right way to do it
Is this the right way to return an object from a function? Car getCar(string
I don't know if Nested python decorator? is the right way to state this
Is this the right way, to use boost::shared_ptr for the nodes left and right
Is this the right way to do a nested navigation? <dl> <dt>Struktur</dt> <dd> <ul
What the right way to interrupt executor's thread? I've got this: Thread class with
Can anyone help me to do this in the right way?I mean.. like that
could someone tell me if this is the right way to do bidirectional mapping?

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.