ScriptManager 控件保留历史哈希值

发布于 2024-10-21 23:50:54 字数 544 浏览 2 评论 0原文

我正在使用 ScriptManager 控件从服务器 Web 服务加载搜索结果。页面上有一个文本框和按钮,用户可以在其中输入搜索词。当他们提交搜索时,将调用搜索页面的 Response.Redirect。我使用 ScriptManager 的历史功能来跟踪用户可以执行的过滤。如果您熟悉此函数,则 URL 最终看起来像这样:

http://somesite/search.aspx?q=giant+dog#color=red&hair=long

我的问题是,如果用户打算使用 search.aspx 页面上的文本框和按钮进行另一次搜索,这会导致response.redirect,则查询字符串发生变化,但哈希历史记录仍是 URL 的一部分。这对我来说没有意义,因为根据我对 Response.Redirect("someURL") 的理解,它应该表现得像是将您发送到一个新页面,无论它是否转到同一页面它离开了。

我知道我可以设置 window.location.hash = "#" 但我希望有一种比服务器端更干净的方法。

请帮忙! :-)

I am using a ScriptManager control to load search results from server web services. There is a text box and button on the page where the user enters their search terms. When they submit their search there is a Response.Redirect that is called to the search page. I use the ScriptManager's history function to track filtering that the users can do. If you are familiar with this function the URL ends up looking something like this:

http://somesite/search.aspx?q=giant+dog#color=red&hair=long

My problem is that if the users deices to do another search with the text box and button on the search.aspx page, which causes a response.redirect, the query string changes but the hash history stay a part of the URL. This does not make sense to me because from what I understand of the Response.Redirect("someURL") it should act like it is sending you to a new page regardless if it is going to the same page it left.

I know I can set window.location.hash = "#" but I was hoping there was a cleaner way than that on the server side.

Please help! :-)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

人心善变 2024-10-28 23:50:54

这是一篇旧帖子,但我想我会添加解决方案,以防其他人正在寻找这个解决方案。我遇到了同样的问题,当进行 Response.Redirect() 调用时,历史记录点在回发到服务器时得到维护。我不确定为什么会发生这种情况,这对我来说似乎违反直觉。但我相信 ScriptManager 正在做一些事情来延续历史点。

答案是将发出 Response.Redirect() 调用的控件放入 UpdatePanel 中。因此,就我而言,我有一个按钮,其中有一个事件处理程序,其中正在发出重定向。如果没有 UpdatePanel,历史记录点将被保留。使用 UpdatePanel 包裹按钮后,一切都按预期工作。

This is an old post, but I thought that I would add the solution in case anybody else was looking for this. I ran into the same problem, where the history point was being maintained across post backs to the server when a Response.Redirect() call was made. I'm not sure why this is happening and it seems counter-intuitive to me. But I believe the ScriptManager is doing something to carry the history point over.

The answer is to put your control that's issuing the Response.Redirect() call in an UpdatePanel. So, in my case, I have a button that has an event handler where a redirect is being issued. Without the UpdatePanel, the history point is preserved. With the UpdatePanel wrapping the button, all works as expected.

信愁 2024-10-28 23:50:54

您可以在Redirect 之前调用ScriptManagerAddHistoryPoint 方法。

You can invoke AddHistoryPoint method of the ScriptManager, before Redirect.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文