ScriptManager 控件保留历史哈希值
我正在使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是一篇旧帖子,但我想我会添加解决方案,以防其他人正在寻找这个解决方案。我遇到了同样的问题,当进行 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 theScriptManager
is doing something to carry the history point over.The answer is to put your control that's issuing the
Response.Redirect()
call in anUpdatePanel
. So, in my case, I have a button that has an event handler where a redirect is being issued. Without theUpdatePanel
, the history point is preserved. With theUpdatePanel
wrapping the button, all works as expected.您可以在
Redirect
之前调用ScriptManager
的AddHistoryPoint
方法。You can invoke
AddHistoryPoint
method of theScriptManager
, beforeRedirect
.