For details about the navigation method, refer to: Several page navigation methods
ASP. NET has the following navigation methods:
| Navigation Method |
Purpose |
| Hyperlink Server Control |
Navigate to another page |
| Response. Redirect () |
UseCodeNavigate to another page. Same functions as hyperlink |
| Server. Transfer () |
End this page and execute another page. Valid only for. aspx pages |
| Server. Execute () |
When the content of this page is displayed, other pages are displayed. The display information of the two pages is displayed together. Valid only for. aspx pages |
| Window. open () |
Open a new page on the client |
The following details:
Hyperlink control:
Receive mouse click events and navigate to the page of hyperlink. navigateurl attribute settings. The basic purpose is navigation, which also includes load, unload, init, and prerender events to perform specific operations.
For example, you can define the application variable name in the unload event of the hyperlink control on a page: Private Void Hyperlinkdomainunload ( Object Sender, system. eventargs E)
{
Application ["Name"]="Pierce";
}
Then read the variable on the navigation page: Private Void Page_load ( Object Sender, system. eventargs E)
{
Response. Write (application ["Name"]);
}
In the original article, the hyperlink control cannot execute any server-side events, but the above Code does execute the server-side code.
Response. Redirect ():
To achieve the purpose of navigation through code, a round-trip process will be generated to interact with the user, and parameters can be passed through strings, such:
Private Void Linkbutton#click ( Object Sender, system. eventargs E)
{
//Display next page.
Response. Redirect ("Nextpage. aspx? Name = Pierce");
}
Server. Transfer ():
Similar to hyperlink and response. Redirect (), the difference is:
Server. Transfer () can retain some information about the source page during the transfer from the source page to the target page. Set the 2nd parameters of transfer () to true so that the viewstate, querystring, and even process information of the source page can be retained on the target page.
Original article: If this function is used, you need to set the enableviewstatemac value of the page to false, that is, the hash operation is not performed. By default, ASP. NET performs hash processing on the viewstate value. Only by disabling enableviewstate = false can the subsequent page read the viewstate information. However, after testing, enableviewstate = true has no effect on reading viewstate information. By default, the characters in viewstate are encoded in base64 format. Although not easy to read, they are not encrypted. You can control the encryption mode in machine. config. The encryption operation must be completed at the machine layer, which consumes system resources. If encryption is performed based on the machinekey, viewstate values cannot be directly read.
Example:
Create a new page webform1.aspx, add the Textbox Control, name TB, add the button control, name button1, TB. Text = "test ", Private Void Button#click ( Object Sender, system. eventargs E)
{
Server. Transfer ("Webform2.aspx",True);
}
Create webform2.aspx, Private Void Page_load ( Object Sender, system. eventargs E)
{
System. Collections. Specialized. namevaluecollection col=Request. form;
Response. Write (COL ["TB"]);
}
Through the test, webform2 will display test, indicating that the viewstate of webform1.aspx is read.
Server. Execute ():
You can execute other pages without leaving the current page. This method displays the execution results of other pages on the current page.
In the original article, enableviewstatemac must be set to false, but the test results show that the value of this option has no effect on execution of execute.
Use
System. Io. stringwriter writer = New System. Io. stringwriter ();
Server. Execute ( " Webform2.aspx " , Writer );
Response. Write (writer. tostring ());
Webform1 displays various controls and execution results of webform2.
Events in webform2 can be executed. If a post-back control event is triggered, the webform1 control is cleared.
Window. open ():
This method exists in the script file, so that the user's browser opens a new window and can only be executed on the client.
For example, create the following HTML button:<InputStyle= "Z-INDEX:
102; left: 55px; width: 81px; position: absolute; top: 156px; height:
24px"Onclick= "Window. Open ('webform2. aspx ')"Type= "Submit"
Value= "New window">
You can open a new window to point to the webform2.aspx page.
Refer:
MS develop web application with Microsoft Visual Basic. NET and Microsoft Visual C #. net
2002