如何重置 ASP.NET 字段中的值?
当前表单位于此处。它并不完整,只有几个选项可行。
选择“Image CD”,然后选择任意分辨率,然后单击“添加到订单”。该订单将记录在服务器端,但在客户端,我需要将产品下拉列表重置为“{select}”,以便用户知道他们需要选择另一个产品。这与子选择消失的想法是一致的。
我不知道是否应该使用 ASP 回发或标准表单提交,并且当用户向订单添加项目时,大多数字段都需要重置。
The current form is here. It is not complete, and only a couple options will work.
Select "Image CD" and then any resolution and click "Add to Order." The order will be recorded on the server-side, but on the client-side I need to reset the product drop-down to "{select}" so that the user will know that they need to select another product. This is consistant with the idea that the sub-selections disappear.
I don't know whether I should be using ASP postback or standard form submittal, and most of the fields need to be reset when the user adds an item to the order.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我会使用 Response.Redirect(Request.RawUrl) 方法从服务器端重置表单数据。
一点解释:这是 PRG 设计模式
此问题的解决方法:
例如,必要的数据可以存储在
Session
中。这意味着我们通过第一个 POST 获取数据,将其放入存储,执行重定向并取回。I'd use
Response.Redirect(Request.RawUrl)
method to reset the form data from the server side.A little explanation: this is PRG design pattern
A workaround for this question:
necessary data may be stored in
Session
for example. This means we getting the data with the first POST, putting it to the storage, performing redirect and getting it back.在表单上的页面加载事件中,您需要添加与此类似的内容:
这将允许您处理订单,但然后重新开始订单表单。
In the pageload event on the form, you need to add something simalar to this:
That will allow you to process the order, but then start over the order form.
最简单的方法是在控件类型上分叉的递归函数,
您可以通过传递
this
在 Load 事件中调用此函数。 (这是假设您想要重置多个控件或一小部分控件)。The simplest means would be a recursive function that forks on the type of control
You would this call this function in your Load event by passing
this
. (This is presuming you want to reset more than a single control or small list of controls).