SoFunction
Updated on 2025-03-06

Summary of C# web page jump method

1. Currently, there are several ways to pass values ​​on the middle page:

(,false); The target page and the original page can be on two servers, and you can enter the URL or relative path. The following bool value is whether to stop executing the current page. Jump to the new page, the original window is replaced. "The URL in the browser is a new path. The method causes the browser to link to a specified URL. When the() method is called, it creates a reply, and the reply header indicates the status code 302 (indicating that the target has changed) and the new destination URL. The browser receives the reply from the server and uses the information in the answer header to issue a request for the new URL. That is to say, the redirect operation occurs on the client when using the method, involving two communications with the server in total (two round trips): the first is a request to the original page, and a 302 answer is obtained, and the second is a request to the new page declared in the 302 answer, which gets the page after the redirection.

("?name=zhangan",true); The target page and the original page can be on the same server. Jump to the new page, the original window is replaced. The URL in the Wave Ball Forum browser remains unchanged. By default, the method does not pass form data or query string from one page to another, but as long as the second parameter of the method is set to Tb310True, the form data and query string of the first page can be retained. At the same time, one thing you should pay attention to when using: the target page will use the response flow created by the original page, which results in machine verification checks b310, Boqiu, Boqiu.com, expert heart, event recommendation, event analysis, database, football matches, basketball, NBA, odds, scores, basketball data, football data.
(Machine Authentication Check, MAC) believes that the ViewState of the new page has been tampered with. Therefore, if you want to preserve the original page's form data and query string collection, the EnableViewStateMac property of the target page's Page directive must be set to False.

("?address=beijing); The target page and the original page can be on the same server. Jump to a new page, and then jump to the original page. The URL in the browser is the original path. When the specified ASPX page is executed, the control process returns to the location where the original page is issued. This page navigation method is similar to a function call for the ASPX page. The called page can access the form data and query string collection of the page issued. Therefore, the EnableViewStateMac property of the page called page must be set to False.

("<script language='javascript'>('');</script>");_ The target page and the original page can be on two servers, and you can enter the URL or relative path. The original window is retained, and a new page is added.

("<script language='javascript'>=''</script>"); Open a new page and the original window is replaced.

("<script>('')</script>");

("<script>('')</script>");

(I) What is the difference between showModalDialog and showModelessDialog?

showModalDialog: After being turned on, the input focus will always be maintained. Unless the dialog is closed, the user cannot switch to the main window. Similar to alert's operation effect. b310,,Boqiu,Boqiu.com,Experts' Heart, Event Recommendation, Event Analysis, Database, Football Events, Basketball, NBA, Odds, Scores, Basketball Data, Football Data showModelessDialog: After being turned on, the user can randomly switch the input focus. It has no effect on the main window (at most it is blocked. :P)

(2) How to prevent the hyperconnection between showModalDialog and showModelessDialog from popping up new windows?  

Just add <base target="_self"> to the opened web page. This sentence is usually placed between <html> and <body>

2. If a large number of parameters are needed between two pages to be passed, such as data query, it is inconvenient to use the method 1-6 to pass the value, and the method 7 does have a unique advantage! However, certain settings are required when using this method. Let me briefly introduce how to use this method:

Take the query data page as an example:

Set the following public attributes () in the query page:

public class QueryPage : 
{
protected  txtStaDate;
protected  txtEndDate;
 ...
/// &lt;summary&gt;
/// Start time/// &lt;/summary&gt;
public string StaDate
{
get{ return ;}
set{ = value;}
}
/// &lt;summary&gt;
/// End time/// &lt;/summary&gt;
public string EndDate
{
get{ return ;}
set{ = value;}
}
....
private void btnEnter_Click(object sender,  e)
{
("");
}
}

On the page showing query results ():

 public class ResultPage : 
{
 private void Page_Load(object sender,  e)
 {
//Convert it to get the data entered in the previous pageQueryPage queryPage = ( QueryPage );
( "StaDate:" );
(  );
( "&lt;br/&gt;EndDate:" );
(  );
 }
}

3. If there are many query pages that share a result page setting method:

The key in this method lies in the conversion of "QueryPage queryPage = (QueryPage );" which can be achieved only when the conversion does not depend on a specific page.

If all query pages inherit an interface and define a method in that interface, the only function of this method is to enable the result page to obtain the parameters required when building the result, and then the operation of sharing a result page with multiple pages can be realized!

1. First define a class and use it to place all query parameters:

/// &lt;summary&gt;
/// The value to be used in the result page/// &lt;/summary&gt;
public class QueryParams
{
private string staDate;
private string endDate;
/// &lt;summary&gt;
/// Start time/// &lt;/summary&gt;
public string StaDate
{
get{ return ;}
set{ = value;}
}
/// &lt;summary&gt;
/// End time/// &lt;/summary&gt;
public string EndDate
{
get{ return ;}
set{ = value;}
}
}

2. Interface definition:

/// &lt;summary&gt;
/// Define the query interface./// &lt;/summary&gt;
public interface IQueryParams
{
/// &lt;summary&gt;
/// Parameters/// &lt;/summary&gt;
QueryParams Parameters{get;}
}

3. The query page inherits the IQueryParams interface():

/// &lt;summary&gt;
///Query page, inherit interface/// &lt;/summary&gt;
public class QueryPage : , IQueryParams
{
protected  txtStaDate;
protected  txtEndDate;
private QueryParams queryParams;
 ...
/// &lt;summary&gt;
/// Parameters used in the result page/// &lt;/summary&gt;
 public QueryParams Parameters
{
get
{
return queryParams;
}
}
....
private void btnEnter_Click(object sender,  e)
{
//AssignmentqueryParams = new QueryParams();
 = ;
 = 
("");
}
}

4. Other pages are also set up

5. Receive page ():

public class ResultPage : 
{
 private void Page_Load(object sender,  e)
 {
QueryParams queryParams = new QueryParams();
IQueryParams queryInterface;
//The page that implements this interfaceif(  is IQueryParams)
{
queryInterface = ( IQueryParams );
queryParams = ;
}
( "StaDate:" );
(  );
( "&lt;br/&gt;EndDate:" );
(  );
 }
}

The above content introduces a summary of the C# web page jump method, I hope you like it.