[英]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: 我更喜欢使用重定向方法,原因如下:
我宁愿清除文本框并将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.