Method 1:
Pass through URL link address
Send. aspx:
Protected void button#click (Object sender, eventargs E)
{
Request. Redirect ("default2.aspx? Username = honge ");
}
Receive. aspx:
String username = request. querystring ["username"]; To obtain the parameter value.
Method 2:
Send. aspx
<Form ID = "form1" runat = "server"Action = "receive. aspx" method = post>
<Div>
<Asp: button id = "button1" runat = "server" onclick = "button#click" text = "button"/>
<Asp: textbox id = "username" runat = "server"> </ASP: textbox>
</Div>
</Form>
Receive. aspx
String username =Ruquest. Form["Receive"];
Method 3:
Send. aspx:
Protected void button#click (Object sender, eventargs E)
{
Session ["username"] = "honge ";
Request. Redirect ("default2.aspx ");
}
Receive. aspx:
String username =Session ["username"]To obtain the parameter value.
Method 4:
Send. aspx:
Protected void button#click (Object sender, eventargs E)
{
Application ["username"] = "honge ";
Request. Redirect ("default2.aspx ");
}
Receive. aspx:
String username =Application["Username"]; To obtain the parameter value.
Method 5:
Send. aspx:
Public string name
{
Get {
Return "honge ";
}
}
Protected void button#click (Object sender, eventargs E)
{
Server. Transfer("Default2.aspx ");
}
Receive. aspx:
Send d =Context. HandlerAs send;
If (D! = NULL)
{
Response. Write (D. Name)To obtain the parameter value.
}
In Asp.net 2.0, you can use the following method:
Previouspage d = context. handler as previouspage;
If (D! = NULL)
{
Response. Write (D. Name); to obtain the parameter value.
}
It can also be used as follows:
Send. aspx:
<Asp:ButtonId = "btnsubmit" runat = "server"Postbackurl = "~ /Reveive. aspx"TEXT = "Submit"/>
Receive. aspx:
<% @PreviouspagetypeVirtualpath = "~ /Default. aspx "%>
String name =Previouspage. NameTo obtain the parameter value.
If masterpage is used in your page, server. the previouspage passed by transfer is invalid. I don't know why. so if masterpage is used, it is best to use session or context. items ["username.
1. response. the redirect method does not jump quickly because it takes two rounds (two PostBack), but it can jump to any page, there is no website page restriction (that is, you can jump from Yahoo to Sina), and you cannot skip logon protection. However, slow speed is the biggest defect! Redirect jump mechanism: First, send an HTTP request to the client. The notification needs to jump to a new page, and then the client sends a jump request to the server. Note that all data stored in the internal space will be lost after the jump, so you need to useSession.
2. server. Transfer is fast. Only one PostBack is required, .... It must be on the same site because it is a server method. In addition, he can skip logon protection. You can try to write a small program: design a jump from page 1 to page 2, but to enter page 2, You need to log on and perform form authentication. However, if the jump statement uses transfer, the logon page will not pop up. The redirection request of this method occurs on the server, so the URL address of the browser still retains the address of the original page!
3. sever.exe cute is mainly used in page design and must be directed to the page under the same site. This method needs to be used to insert the output results of a page to another ASPX page. Most of them are in the table, where a page is nested to another page.
Summary:
When you need to redirect a user to a page on another server, use redirect
When you need to redirect a user to a non-ASPX page, such as HTML, use redirect
When the query string needs to be retained to the server as part of the URL, because the other two methods cannot achieve two PostBack operations, the data is first brought back to the server, and the Redirect
Switch between aspx pages (logon not involved), use transfer
Execute is used to insert the output result of the ASPX page to another ASPX page.
Of course, I forgot another hyperlink! Of course, you don't need to talk too much about this. He uses hyperlinks when a user needs to decide when to jump to a page.
By the way, how to use the Redirect method to use Chinese Characters in query strings is often garbled because URLs do not support Chinese characters. In this case, the conversion is required:
The following is a reference clip:
String message = server. urlencode ("welcome to the racing column "); |
First convert and then use the query string
The following is a reference clip:
Response. Redirect ("webform2.aspx? MSG = "+ message ); |