Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET TextBox Control - Get the default text value in code behind?

I have been spying the MSDN and can't see a property/method for TextBox that allows you to get the default text value that was set on a field; I want to be able to compare the current txtMyTextBox.Text to the default value (like this psuedo code shows):

var myValue = (String.Compare(txtMyTextBox.Text, txtMyTextBox.DefaultText) ? "" : txtMyTextBox.Text)

Is this something which exists in the ASP.NET control? Or am I asking too much? :)

Thanks for any help (as always)!

Pete

like image 752
peteski Avatar asked Feb 24 '26 09:02

peteski


2 Answers

By DefaultText do you mean the initial text before editing?

Perhaps declare this in a constant / field / etc somewhere, and set it programatically rather than in the markup - i.e. in the first load, txtMyTextBox.Text = defaultText; - then later you can just compare again to defaultText to track changes.

like image 175
Marc Gravell Avatar answered Feb 25 '26 21:02

Marc Gravell


There is no "DefaultText" property on a textbox (or any other control). You probably have defined the default through a constant string, so just compare the Text property to that constant string.

like image 25
LeJeune Avatar answered Feb 25 '26 22:02

LeJeune