如何使用 asp.net c# 保留过滤器的值及其结果?
问题:-
页面是一个典型的搜索页面,上面几乎没有过滤器。当基于过滤器搜索记录时,它会在 Gridview 中显示结果。在网格视图记录中,用户可以单击任何记录来查看详细信息,并将焦点放在新页面上。 到目前为止它运行良好。 现在,当用户从详细信息页面返回到搜索页面时。我丢失了选定的过滤器值,并且网格视图中没有结果。 当用户返回搜索页面时,如何在 gridview 中显示选定的过滤器及其结果?有什么例子等吗?
仅供参考,我正在使用会话将参数传递给 ObjectDatasource。
Question:-
Page is a typical search page with few filters on it. When search for records based on filters, it shows result in Gridview. From grid view records, user can click on any record to see the details which takes the focus on new page.
Its working fine so far.
Now when user comes back from details page to search page. I am loosing selected filters values and no result in grid view.
How can i display selected filters and its results in gridview when user is coming back on search page? Any example etc.?
FYI, I am using sessions to pass parameters to the ObjectDatasource.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
将搜索参数存储在 cookie 或会话变量中。当用户返回到搜索屏幕时,使用这些参数。
Store the search parameters in either a cookie or a session variable. When the user returns to the search screen, use those parameters.
如果您在返回搜索页面时丢失了值,我假设您让用户通过链接、菜单等导航到搜索页面?在这种情况下,当浏览器加载 URL 时,搜索页面将首次加载(预期行为)。
您有几个选项来保留信息:
1。会话:当填写初始搜索表单并且页面回发时,将表单值保留/存储在会话中。然后修改页面,使其在初始加载时查找那些会话值并绑定网格。这将使价值观得以持续。
松散示例:
上述唯一的问题是,您将在网格中丢失客户端状态,因此,如果网格具有分页等功能,并且用户最初位于第 4 页,则当上述绑定时,它将返回页面1. 您可以通过在用户单击网格中的链接时在会话中存储状态信息来解决此问题(假设网格导致回发而不是直接客户端导航到详细信息页面)。您可以存储页码、排序列等,并在用户返回时应用这些内容。
2.历史记录/Javascript:如果您的搜索的导航结构 ->详细信息页面是这样的,您在详细信息页面上有一个“返回搜索”链接,并且您确信加载详细信息页面的唯一时间是通过搜索 -> 。详细信息,那么您可以依靠 javascript 使历史后退一步。我相信浏览器将保留上一页(搜索页面)的状态并允许用户继续使用它。
松散示例(详细信息页面标记):
或
以上未经测试,但理论上可能有效。它将允许用户单击链接,或使用浏览器中的后退按钮达到相同的效果。同样,它仅在理论上有效,如果您有一个非常受控的工作流程,您可以保证用户从搜索页面到达详细信息页面。
只是一些想法...
If you're losing the values when you return to the search page, I assume your having the user navigate to the search page via a link, menu, etc.? In this case when the URL is loaded in the browser the search page loads for the first time (expected behavior).
You have a few options to persist the information:
1. Session: When the initial search form is filled out and the page posts back, persist/store the form values in session. Then modify the page such that it looks for those session values on initial load and binds the grid. This would allow the values to persist.
Loose Example:
The only issue with the above is that you will lose client-state in your grid, so if the grid has paging, etc. and the user was on page 4 originally, when the above binds it'll be back on page 1. You could get around this by also storing state information in session when the user clicks a link in the grid (assuming the grid causes a postback and not a direct client-side navigation to the details page). You could store page #, sort column, etc. and apply these when the user returns.
2. History/Javascript: If the navigation structure of your search -> details pages is such that you have a 'back to search' link on the details page, and you are confident that the only time the details page is loaded is through search -> details, then you could rely on javascript to step back one step in history. I believe the browser would then retain the state of the previous page (the search page) and allow the user to continue using it.
Loose Example (details page markup):
or
The above is untested but in theory may work. It would allow the user to click the link, or use the back button in their browser to the same effect. Again it would only work in theory if you have a very controlled workflow where you can guarantee the person arrived at the details page from the search page.
Just some ideas...