Can I use AJAX to clear a TextBox before its contents are sent to the server
Posted on 2007-10-18
I have a website developed using VC#.NET and ASP.NET 2.0
The site contains a page that contains 2 text boxes and a button.
In the 1st text box the user types or pastes the input data. This can be a lot of text data typically over 20K
When the user press the button the text in the 1st text box is sent to the server where it is processed. The answer is returned to the client and displayed in the 2nd text box. Again the amount of data sent to , and displayed in, the 2nd text box can be a large amount maybe over 20K.
Im trying to minimize the amount of data sent to the server. For example if the user presses the button AGAIN then the data in the 2nd text box (the results data as a result of the previous button press) is sent to the server even though thats not required. Its only the data in the 1st text box (the input data) that should be sent. But thats how ASP.NET works. Setting ENABLEVIEWSTATE to false for the textbox doesnt work because text boxes are handled differently. The contents of the textbox are sent anyway.
So what I want is this. If there is data in the 2nd text box then, when the user presses the button, I want it to be somehow cleared so that NO DATA is sent to the server from this text box. Can this be done using AJAX. If so how and which control would I use?
PLEASE NOTE: Ive already tried the obvious thing which is
TextBox2.Text = "" in the button_click event. This of course doesnt work!