简体   繁体   中英

Clearing text fields on vb.net project vs2008

Summary: web page has a few fields to allow the user to enter payments. After the system processes the payments, the fields weren't cleared out. So my task is to simply clear them out. This is the few lines of code:

' first insert the transaction
InsertANewTransaction()

'clear out the values
txtAddTransAmount.Text = ""
ddlAddTransTypes.SelectedIndex = -1
txtComment.Text = ""

' then create and print the receipt
Payment2MsWordDoc(Payment, PaymentType, PreviousBalance, NewBalance, DueDate, ProjMinPayment)

I added the three lines in the middle resetting the values. Problem is, they don't reset. Doing some debugging the file lines of the Payment2MsWordDoc procedure are the culprit:

Response.AppendHeader("Content-Type", "application/msword")
Response.AppendHeader("Content-disposition", "attachment; filename=" + fileName)
Response.Write(strBody)

The procedure is writing an HTML receipt into the strBody and displaying it to the user. They see the 'File download, do you want to open or save this file....' and can open the receipt in ms-word. Without those three lines, the resetting works. So clearly they are messing up something, I just don't understand what.

I've got a workaround, but I'd like to know what is going on. Even to the tune of is this a correct way of creating/downloading a document. This in an inherited system, the original designer is long gone. I'm not strong in either VB or web apps so am clueless as to what the problem is.

Imagine you have a textarea on a webpage and then a regular hyperlink to a word document below that. If you type into the textarea and then click the link, do you expect the textarea to clear out? No, the browser will just launch the word document and leave the page as is. The same thing is happening with your form. Upon submit, the server is just sending a word document and since the server hasn't sent any new HTML the browser just stays as is. All of your clearing out of textfields doesn't matter because the new state is never sent down the wire. What you need to do is to send the browser new HTML and not the word doc. In the new HTML you can include a meta redirect to the word doc or better yet a download link.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM