简体   繁体   English

清除vb.net项目vs2008上的文本字段

[英]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: 罪魁祸首是对Payment2MsWordDoc过程的文件行进行一些调试:

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. 该过程是将HTML收据写入strBody并将其显示给用户。 They see the 'File download, do you want to open or save this file....' and can open the receipt in ms-word. 他们会看到“文件下载,您要打开还是保存此文件...。”并可以以ms字打开收据。 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. 我在VB或Web应用程序方面都不强,因此对于问题出在哪里一无所知。

Imagine you have a textarea on a webpage and then a regular hyperlink to a word document below that. 想象一下,您在网页上有一个文本区域,然后有一个指向该文件下方的word文档的常规超链接。 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. 不,浏览器将只启动word文档,并按原样保留页面。 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. 提交后,服务器仅发送Word文档,并且由于服务器未发送任何新的HTML,因此浏览器保持原样。 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. 您需要做的是向浏览器发送新的HTML,而不是doc这个词。 In the new HTML you can include a meta redirect to the word doc or better yet a download link. 在新的HTML中,您可以包括指向文档doc或更好的下载链接的元重定向。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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