简体   繁体   English

ASP.net:处理清除页面的最佳方法是什么?

[英]ASP.net: what's the best way to handle clearing a page?

I have a page for searching and the search result will be shown in gridview control. 我有一个搜索页面,搜索结果将显示在gridview控件中。 I have a button called Clear to clear out the search result in gridview and also the text box where user enter the search criteria. 我有一个名为“清除”的按钮,以清除gridview中的搜索结果,还有一个用户输入搜索条件的文本框。

At first, i did the Clearing by doing page refresh print("Response.Redirect(~/blah/search.aspx"); but i'm not sure if that's the best way to clear a page. Would it be better to set the text box to string empty and set the gridview datasource to Nothing then bind it? 起初,我通过执行页面刷新print("Response.Redirect(~/blah/search.aspx");来进行清除print("Response.Redirect(~/blah/search.aspx");但是我不确定这是否是清除页面的最佳方法。设置是否会更好文本框为空字符串,并将gridview数据源设置为Nothing,然后将其绑定?

I prefer the redirect method for several reason: 我更喜欢使用重定向方法,原因如下:

  1. Use can hit back and get their data back. 使用可以反击并取回其数据。
  2. Less code to maintain an remember about when you change the page. 较少的代码可让您记住更改页面的时间。 (If you add a new field will you remember to clear that also?) (如果添加新字段,您还记得要清除吗?)

我宁愿清除文本框并将gridview绑定到一个空列表。

The best way to do this is not do it at all. 做到这一点的最好方法是根本不做。

Try to design the search box/button so that it is obvious that you can initiate a new search just by typing in the text box and clicking the search button. 尝试设计搜索框/按钮,这样很明显,您只需在文本框中键入并单击搜索按钮即可启动新搜索。 Take a cue from google. 从谷歌那里获取灵感。 It is likely that most of your users are familiar with this behavior already. 您的大多数用户可能已经熟悉此行为。

If starting from scratch rather than refining the current search is the most common behavior of a user, then you could use some javascript to clear the search box on focus. 如果从头开始而不是优化当前搜索是用户最常见的行为,那么您可以使用一些JavaScript来清除焦点对准的搜索框。 Or less intrusively, you could just select the text on focus to enable type-over style clearing. 或以较少干扰的方式,您可以选择重点突出的文本来启用键入样式的清除。

onFocus="this.select()"

There shouldn't be any reason to waste your server's cpu/bandwidth, or your user's time just to search from a blank page. 不应有任何理由浪费服务器的CPU /带宽,或浪费用户的时间仅从空白页进行搜索。

我通常只创建一个指向“搜索新页面”的链接(因为您是从头开始,而不仅仅是清除表单,这是“清除”对我的隐含含义),该链接指向搜索页面,而不是一个提交按钮,以避免不必要的回发,仅用于重定向。

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

相关问题 在ASP.Net中处理web.config文件版本的最佳方法是什么? - What's the best way to handle web.config file versions in ASP.Net? 在ASP.Net应用程序中处理长时间运行的最佳方法是什么? - What's the best way to handle long running process in an ASP.Net application? 什么是处理异常以及如何在asp.net中处理它们的最佳方法 - What's the best way to handle the exceptions and how to deal with them in asp.net 使用Masterpage在ASP.Net页面上进行JavaScript验证的最佳方法是什么? - What's the best way to do javascript validation on ASP.Net page with Masterpage? 在ASP.Net中编码重定向到SSL页面的最佳方法是什么 - What is the best way to code a redirect to SSL page in ASP.Net 在 ASP.NET 上检测 JSON 请求的最佳方法是什么 - What's the best way to detect a JSON request on ASP.NET 在ASP.NET中检查用户浏览器的最佳方法是什么? - What is the best way to check the user's browser in ASP.NET? 在ASP.NET中显示随机图像的最佳方法是什么? - What's the best way to show a random image in ASP.NET? 在ASP.NET中显示缩略图的最佳方法是什么? - What's the best way of displaying thumbnails in ASP.NET? 在ASP.net中实现友好URL的最佳方法是什么? - What's the best way to implement friendly URL in ASP.net?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM