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?

0
AppDevForMe
9/3/2007 3:13:45 PM
asp.net.web-forms 93655 articles. 5 followers. Follow

3 Replies
519 Views

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....

 

e.g.

bool HasTextChanged ;
 

Protected MyText_TextChanged((object sender, EventArgs e)

{

    HasTextChanged  = true;
}
 

0
richiej
9/3/2007 3:37:11 PM

Hi,

Use the TextChanged event :

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

</asp:TextBox>

In the code behind

protected void DetectChange(object sender, EventArgs e)
{
    // Your code
}
 
HTH,
Suprotim Agarwal
-----
http://www.dotnetcurry.com
-----

ASP.NET Grid With Excel Capabilities | 27 GridView Tips & Tricks | Hosting your site? | SQL Server Tips
0
Suprotim
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.
0
Hong
9/5/2007 3:26:12 AM
Reply: