清除 vb.net 项目 vs2008 上的文本字段 [英] Clearing text fields on vb.net project vs2008

查看:20
本文介绍了清除 vb.net 项目 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)

我在中间添加了三行重置值.问题是,他们不重置.对 Payment2MsWordDoc 过程的文件行进行一些调试是罪魁祸首:

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)

该过程将 HTML 收据写入 strBody 并将其显示给用户.他们会看到文件下载,您要打开还是保存此文件...."并且可以在 ms-word 中打开收据.没有这三行,重置工作.很明显他们搞砸了一些事情,我只是不明白是什么.

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.

我有一个解决方法,但我想知道发生了什么.甚至可以说这是创建/下载文档的正确方法.这在一个继承的系统中,原来的设计者早已不在了.我不擅长 VB 或 Web 应用程序,因此对问题所在一无所知.

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.

推荐答案

假设您在网页上有一个 textarea,然后有一个常规超链接到它下面的 word 文档.如果您在 textarea 中键入然后单击链接,您是否希望 textarea 清除?不,浏览器只会启动 word 文档并保持页面不变.同样的事情也发生在你的表单上.提交时,服务器只是发送一个 word 文档,由于服务器没有发送任何新的 HTML,浏览器只是保持原样.您清除文本字段的所有内容都无关紧要,因为新状态永远不会通过网络发送.您需要做的是向浏览器发送新的 HTML,而不是单词 doc.在新的 HTML 中,您可以包含指向 doc 一词的元重定向或更好的下载链接.

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.

这篇关于清除 vb.net 项目 vs2008 上的文本字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆