SoFunction
Updated on 2025-04-12

Page 2/2


5. Receive page (): public class ResultPage:
{
private void Page_Load(object sender,  e)
{

QueryParams queryParams = new QueryParams();
IQueryParams queryInterface;
//The page that implements this interface
if(  is IQueryParams)
{
queryInterface = ( IQueryParams );
queryParams = ;
}

( "StaDate:" );
(  );
( "<br/>EndDate:" );
(  );
}
}
3. Cause of this article:
Because I have to do a data query in my work, the parameters are a lot of troublesome. I used the Session to pass it. After using the parameters sent by the Session, I still need to clean the Session. Before using the Session, I have to judge whether the Session exists. It is extremely cumbersome. I think there should be a simpler way to implement parameter transfer between pages. Therefore, I searched online and finally found such a way to implement parameter transfer between pages.
If there are any problems, please correct me!
 ================================================================================== 
First, let’s look at the HttpContext class:
Classes inherit from, understood by class names, that is, Http context class.

This class encapsulates all HTTP specific information about a single HTTP request. This class provides a reference to the HttpContext object of the current HTTP request for classes that inherit the IHttpModule and IHttpHandler interfaces. This object provides access to the requested internal Request, Response, and Server objects.

Common public properties of the HttpContext class are:
Application, obtains the HttpApplicationState object for the current HTTP request.
Current, Get the HttpContext object for the current HTTP request.
Handler, get or set the IHttpHandler object for the current HTTP request.
Items, gets a key value collection that can be used to organize and share data between IHttpModule and IHttpHandler during the HTTP request process.
Request, obtains the HttpRequest object for the current HTTP request.
Response, gets the HttpResponse object for the current HTTP response.
Server, obtains the HttpServerUtility object that provides methods for processing web requests.
Session, gets the HttpSessionState instance for the current HTTP request.

The current object can be obtained through the Context property of the Page class


Next, let’s look at the () method:
Through the Server property class of the Page class, you can transfer to another page, such as (""), and you can jump to a new page.
Using () to jump to the page, the client's URL will not change. It just executes a new page and outputs it on the server side. Therefore, you can obtain the object, form data and query strings passed by the request page by obtaining it in the new page.

Assume that the current page is (class name is FormerPage), the new page to be redirected is
The code from jump is as follows:
private void  btnToNewPage_Click(object sender,  e)
{
   ArrayList list = new ArrayList(3);
   ("This list ");
   ("is for ");
   ("FormerPage to see.");

   ["FormerPageList1"] = list;

   ("");
}
The passed data is obtained through the following code in the new page()Page_Load() event:

if(!IsPostBack)
            {
                try
                {
                    FormerPage former = (FormerPage);                
=;//Get the ClassName public property defined in FormerPage

//Get the ArrayList added in the context dictionary in FormerPage: ["FormerPageList1"]
//Get the Contex dictionary item and cast the type:
                    ArrayList list = ["FormerPageList1"] as ArrayList; 

DataSet ds = ();  //Calling the GetDataSet() public method defined in FormerPage
                     = ds;
                    ();
                }
                catch
                {
                    ("Error get data from parent transfer page!");
                }

            }
Note that the above attributes are used to obtain the IHttpHander object of the current Http request and cast it into a FormerPage object:
FormerPage former = (FormerPage);


Later, you can directly call the public properties and methods of this class. At the same time, you can call the Context dictionary item (Dictionary Item) added in FormerPage.

It is worth noting that when passing page data and receiving data, the instance of the previous page can be correctly obtained when the page is loaded for the first time, and when postback, the instance of the current page will be obtained.

For example, in this article, the FormerPage object can be obtained when loading the first time, and trying to obtain the FormerPage during postback will throw an exception, because when postback, the request page has changed and is no longer a request issued by FormerPage, but a request issued by its own NewPage. We can add the following code to Page_Load() to determine which page the Http request is issued by:
  string path = ; 
            ("<script>alert('Request from:" + path + "');</script>");
In addition, () has an overloaded method (string newpage, bool preserveForm), the second parameter is used to specify whether to retain and collect. If true, the Form and QueryString of the original page are still valid in the new page and can be called. For example:

string str = "Value of Textbox:"+["TextBox1"] +"<br>";
Previous page12Read the full text