gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 18:48:30 24 4
gpt4 key购买 nike

我有 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com