阻止 ASP.NET 回发显示为单独的页面?
我有一个 ASP.NET 表单,用户可以对其进行大量更改,每次更改时,页面 PostsBack 和详细信息都会更新。
如果用户点击浏览器后退按钮,他们将返回该页面的所有先前版本。
是否可以阻止浏览器将每个回发视为新页面?
因此,他们会做出他们喜欢的任何更改,如果他们点击后退按钮,会将他们带到以前的表单,而不是相同的表单,而是不同的版本?
我知道我可以使用 AJAX 来更新值,但我不是高级编码员,因此尝试让事情保持简单,因为我以前没有使用过 AJAX。
I have an ASP.NET form that the user can make lots of changes to, each time they make a change the page PostsBack and the details are updated.
If the user hits the browser back button they go back through all the previous versions of the page.
Is it possible to stop each PostBack being treated by the browser as a new page?
So the would make any changes they like and if they hit the back button it brings them to the previous form and not the same form but a different version?
I know I could use AJAX to update values but I'm not an advanced coder so trying to keep things simple as I haven't used AJAX before.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
Ajax 是您唯一的解决方案。
无法从浏览器历史记录中删除页面。 Javascript 被明确拒绝该功能。
现在,您有可能完全阻止他们使用后退按钮。尽管这可能会导致用户不满意,而且我不能 100% 确定它适用于所有浏览器。
Ajax is your only solution.
There is no way to remove a page from the browser history. Javascript is explicitly denied the capability.
Now, you could, potentially, stop them from using the back button at all. Although this might result in unhappy users and I'm not 100% certain it works in all browsers.
你可以使用一个技巧来做到这一点。
在回发时,您可以将会话位设置为 true,表示他们提交了该表单。在回发时检查该值是否已设置。如果是,他们会再次尝试这样做,您可以中止它。它本身不会阻止回发,但您可以控制逻辑并阻止它执行任何操作。
我个人会探索 ajax,因为 Jquery 提供了一些很好的方法来做到这一点,这将是一次学习经历,但我认为这会按照您的要求工作。以每个会话为基础。如果您只想提交 1 次,请使用数据库来存储活动。
You could use a trick to do it.
On postback you can set a session bit to true saying they submitted that form. On your postback check to see if that value is set. If it is they are trying to do it again and you can just abort it. It wouldn't prevent the postback per se but you could control the logic and prevent it from DOING anything.
I personally would explore ajax as Jquery provides some nice ways to do it and it'd be a learning experience but I suppose this would work as you are asking. On a per session basis. If you only want 1 submission ever use a database to store the activity.
您可以使用 UpdatePanel: http://msdn.microsoft.com/en-us/库/bb386454.aspx
You could use UpdatePanel: http://msdn.microsoft.com/en-us/library/bb386454.aspx