I have a page for searching and the search result will be shown in gridview control. 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控件中。我有一个名为Clear的按钮,用于清除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?
起初,我通过页面刷新打印(“Response.Redirect(〜/ blah / search.aspx”)来完成清除;但我不确定这是否是清除页面的最佳方式。设置是否更好字符串为空的文本框并将gridview数据源设置为Nothing然后绑定它?
4 个解决方案
#1
I prefer the redirect method for several reason:
我更喜欢重定向方法有几个原因:
- Use can hit back and get their data back.
- 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?)
使用可以回击并获取他们的数据。
更改代码以保持记住何时更改页面。 (如果你添加一个新字段,你还记得清除它吗?)
#2
I would rather clear the text box and bind the gridview to a empty list.
我宁愿清除文本框并将gridview绑定到空列表。
#3
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. Or less intrusively, you could just select the text on focus to enable type-over style clearing.
如果从头开始而不是优化当前搜索是用户最常见的行为,那么您可以使用一些javascript来清除焦点上的搜索框。或者不那么具有侵入性,您可以选择焦点上的文本以启用类型转换样式清除。
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 /带宽,或者你的用户只是从空白页面搜索。
#4
I usually just make a link that says "New Search" (since you are starting over, and not just clearing the form, which is what "Clear" would imply to me) that points to the search page instead of a submit button to avoid an unnecessary postback just to redirect.
我通常只是创建一个“新搜索”链接(因为你重新开始,而不只是清除表单,这是“清除”对我意味着什么)指向搜索页面而不是提交按钮以避免一个不必要的回发只是为了重定向。
#1
I prefer the redirect method for several reason:
我更喜欢重定向方法有几个原因:
- Use can hit back and get their data back.
- 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?)
使用可以回击并获取他们的数据。
更改代码以保持记住何时更改页面。 (如果你添加一个新字段,你还记得清除它吗?)
#2
I would rather clear the text box and bind the gridview to a empty list.
我宁愿清除文本框并将gridview绑定到空列表。
#3
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. Or less intrusively, you could just select the text on focus to enable type-over style clearing.
如果从头开始而不是优化当前搜索是用户最常见的行为,那么您可以使用一些javascript来清除焦点上的搜索框。或者不那么具有侵入性,您可以选择焦点上的文本以启用类型转换样式清除。
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 /带宽,或者你的用户只是从空白页面搜索。
#4
I usually just make a link that says "New Search" (since you are starting over, and not just clearing the form, which is what "Clear" would imply to me) that points to the search page instead of a submit button to avoid an unnecessary postback just to redirect.
我通常只是创建一个“新搜索”链接(因为你重新开始,而不只是清除表单,这是“清除”对我意味着什么)指向搜索页面而不是提交按钮以避免一个不必要的回发只是为了重定向。