Is their a way to check if text in a text box has changed?

On a particular web form I wrote, I have a multi line textbox where people enter text/content. When the page loads, it defaults to the text that they had previously entered into the text box. The user then if they wish may change the contents of the text and then press a "save" buttton. I want to do the following:

1. Somehow check if the text in the textbox has changed. If it has changed from the original text, then save the new text to a file.

So the big question here is how do I check to see if the text in the textbox has changed. Is their a method call that can do this? Or do I have to do a string comparison between the old content and new content?

9/3/2007 3:13:45 PM 93655 articles. 5 followers. Follow

3 Replies

Similar Articles

[PageSpeed] 36

Look at the event properties of a textbox, there is one called TextChanged.

 Have it so that when they change text, they call this event. Then have a boolean property and sets that to true (boolean types are false by default, which means when the page is first loaded it will already be false)

Then test to see the value of the property  when user naviagates away etc....



bool HasTextChanged ;

Protected MyText_TextChanged((object sender, EventArgs e)


    HasTextChanged  = true;

9/3/2007 3:37:11 PM


Use the TextChanged event :

<asp:TextBox id="TextBox1" runat="server" AutoPostBack="true" OnTextChanged="DetectChange" >


In the code behind

protected void DetectChange(object sender, EventArgs e)
    // Your code
Suprotim Agarwal

ASP.NET Grid With Excel Capabilities | 27 GridView Tips & Tricks | Hosting your site? | SQL Server Tips
9/3/2007 3:41:30 PM

Hi AppDevForMe,

If the TextBox get the value by user input, you can use the event of TextBox_TextChanged to solve your problem;

If not, I suggest you use JavaScript write a comparison method to solve your problem, that is because set the value to the TextBox by program can not fire the event of TextBox_TextChanged.

Please correct me if I have misunderstood your mean, please LET ME KNOW. Thanks,

Hope it helps,

Hong Gang

Hong-Gang Chen
Microsoft Online Community Support
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
9/5/2007 3:26:12 AM