Setting a decimal textbox field to blank

I have a decimal textbox field that when first displayed is just blank. User enters 499.40 whatever. Clicks "clear fields" and I want to reset this field back to blank, not to zero...

I have below code but not sure how to do it. I want it to equal to 'string.Empty" BUT NOT to zero...
//property
private decimal? StartSalary
    {
        get
        {


            decimal? salaryValue = null;
            if (!string.IsNullOrEmpty(txtJobStartSalary.Text))
                salaryValue = Decimal.Parse(txtJobStartSalary.Text);
            return salaryValue;

        }

        set { txtJobStartSalary.Text = Convert.ToString(value); }
    }

// in clear submit button
StartSalary = 0; //BUT i want it to be blank not zero

Open in new window

LVL 7
CamilliaAsked:
Who is Participating?
 
NazoUKConnect With a Mentor Commented:
set { txtJobStartSalary.Text = value==0 ? "" : Convert.ToString(value); }

I'd probably use null as the value that clears the textbox too though as you've used that in the get, it keeps the logic similar.
0
 
the_billConnect With a Mentor Commented:
modify Your set

//property
private decimal? StartSalary
    {
        get
        {
            decimal? salaryValue = null;
            if (!string.IsNullOrEmpty(txtJobStartSalary.Text))
                salaryValue = Decimal.Parse(txtJobStartSalary.Text);
            return salaryValue;

        }

        set { txtJobStartSalary.Text = (value==0) ? String.Empty : (string)value; }
    }

// in clear submit button
StartSalary = 0; //BUT i want it to be blank not zero
0
All Courses

From novice to tech pro — start learning today.