javascript - 为什么不是 Server.Transfer 为什么只有 Response.Redirect

标签 javascript asp.net

我有 2 个文本框和一个按钮以及一个 Href 标签,可以在点击它时打开日历。和我在另一页上的一样

我使用 Respose.Redirect 编写了一段代码来传输到特定页面,如下所示

protected void Button1_Click3(object sender, EventArgs e)
{
    Response.Redirect("Demo/Default.aspx");//Works fine
    //Server.Tranfer("Demo/Default.aspx"); // Does not works
}

这很干净,但是如果我在第二页上使用 Sever.Tranfer,当用户点击 Href 标签时我无法加载日历控件

最佳答案

http://www.developer.com/net/asp/article.php/3299641/ServerTransfer-Vs-ResponseRedirect.htm

Firstly, transferring to another page using Server.Transfer conserves server resources. Instead of telling the browser to redirect, it simply changes the "focus" on the Web server and transfers the request. This means you don't get quite as many HTTP requests coming through, which therefore eases the pressure on your Web server and makes your applications run faster.

But watch out: because the "transfer" process can work on only those sites running on the server, you can't use Server.Transfer to send the user to an external site. Only Response.Redirect can do that.

Secondly, Server.Transfer maintains the original URL in the browser. This can really help streamline data entry techniques, although it may make for confusion when debugging.

That's not all: The Server.Transfer method also has a second parameter—"preserveForm". If you set this to True, using a statement such as Server.Transfer("WebForm2.aspx", True), the existing query string and any form variables will still be available to the page you are transferring to.

For example, if your WebForm1.aspx has a TextBox control called TextBox1 and you transferred to WebForm2.aspx with the preserveForm parameter set to True, you'd be able to retrieve the value of the original page TextBox control by referencing Request.Form("TextBox1").

关于javascript - 为什么不是 Server.Transfer 为什么只有 Response.Redirect,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4679020/

相关文章:

javascript - 如何在 JavaScript 中编写一个永远不会抛出 "Cannot read property ' * *' of undefined' 的模拟对象

javascript - 手动反转数组

javascript - Bootstrap 轮播不会滚动/加载

javascript - 混合图表中的顶点图表图表顺序

c# - Azure Blob 容器 - 上传具有相同名称属性的 Blob

javascript - ASP 处理程序未向托管环境中的 ajax 调用返回错误消息

asp.net - SQL - 两个不同长度的字符串之间的相似性

javascript - 除非在网格上单击下一行,否则值不会绑定(bind)到下拉提供程序

javascript - 在 Sortable.js 中拖放列表 : How to set a different drop area than a Sortable list?

c# - 调用 TLS 1.0 和 TLS 1.2 Web 服务的 ASP.NET 应用程序