Can I use AJAX to clear a TextBox before its contents are sent to the server

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!

Thanks
rangers99Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

TSmoothCommented:
You don't necessarily need to use AJAX, just need to use Javascript. Set the button's OnClientClick attribute = to a javascript function called something like "ClearTextbox2" and then in that javascript function, clear the text box.

javascript:

function ClearTextBox()
        {
            var txt = document.getElementById('TextBox1');
            txt.value = '';
            return true;
        }

Your button would look something like this:
<asp:Button ID="Button1" runat="server" OnClientClick="javascript: return ClearTextBox();"
            Text="Button" />
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
nisarkhanCommented:
as TSmooth said, you dont really need ajax to clear the textbox but if you really want to use then....

drag and dropt he updatepanel from ajax tool and inside the updatepanel add controls like textbox or any other then wire your event and in that event you write something like this:

textbox.text = string.empty(); or textbox.text = "";

hth
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.