[英]What technology allows page content to change without changing the URL?
I have seen this on some survey websites. 我已经在一些调查网站上看到了这一点。 What is the C# code they use on the client side to keep the URL same, but when clicking the "Next" button, the same aspx page is maintained
他们在客户端使用什么C#代码来保持URL不变,但是当单击“下一步”按钮时,将保持相同的aspx页
Can anyone give a code-wise example how to achieve this? 谁能举一个明智的例子来实现这一目标?
My main query is how is this done in code-behind to change data of page and maintain same url. 我的主要查询是如何在后台代码中完成此操作以更改页面数据并保持相同的url。
Nothing simpler that a session, maintainted at the server side. 在服务器端维护会话最简单。 Store a "current question number" in session, increment it at each succesfull postback and you have what you ask about.
在会话中存储“当前问题编号”,在每次成功回发时将其递增,您就可以提出要求。
Another possibility - a cookie which contains "current question number". 另一种可能性-包含“当前问题编号”的cookie。
Both cookie and session are invisible in the query string of course. 当然,cookie和会话在查询字符串中都是不可见的。
"change data of page and maintain same url." “更改页面数据并保持相同的URL。” Answer is Server.Transfer .
答案是Server.Transfer 。 This method will preserve url.
此方法将保留网址。
The Next button may submit a form using the HTTP POST method. 下一步按钮可以使用HTTP POST方法提交表单。 The form data may contain the session, question and response data.
表单数据可能包含会话,问题和响应数据。 The site uses that to build a new response.
该网站使用它来构建新的响应。 Unlike a GET, a POST does not incorporate data into the URL.
与GET不同,POST不会将数据合并到URL中。
Developers will typically accomplish this task by using AJAX. 开发人员通常将使用AJAX完成此任务。 The basic premise behind it is that only a certain portion of the page (eg a grid or content area) will make a server call and retrieve the results (using Javascript).
它的基本前提是页面的仅特定部分 (例如网格或内容区域)将进行服务器调用并检索结果(使用Javascript)。 The effect achieved is that there has not been a full post back, which is why you don't see the URL or parameters changing.
实现的效果是没有完整的回发,这就是为什么您看不到URL或参数发生更改的原因。
It is possible to do this using jQuery, pure Javascript, or Microsoft's UpdatePanel . 可以使用jQuery,纯Java 脚本或Microsoft的UpdatePanel进行此操作 。
oleksii's comment has some good links as well: oleksii的评论也有一些很好的链接:
That's the AJAX magic.
那就是AJAX的魔力。 There are many JQuery plugings for this, for example this one with a live demo .
有许多JQuery的plugings这一点,比如这一个有现场演示 。 You can also program it easily using JQuery Get or Post or any other wrapper that use XmlHttpRequest object.
您也可以使用JQuery Get或Post或任何其他使用XmlHttpRequest对象的包装器对其进行轻松编程。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.